package com.hongxun.modules.bss.controller;

import java.io.*;
import java.lang.reflect.InvocationTargetException;
import java.math.BigDecimal;
import java.net.MalformedURLException;
import java.util.*;
import java.util.List;

import com.hongxun.common.utils.*;
import com.hongxun.common.validator.ValidatorUtils;
import com.hongxun.common.validator.group.AddGroup;
import com.hongxun.common.validator.group.UpdateGroup;
import com.hongxun.config.PriceConfig;
import com.hongxun.modules.api.entity.BEstimateEntity;
import com.hongxun.modules.api.entity.BOtherCostEntity;
import com.hongxun.modules.api.entity.BProjectApplicationEntity;
import com.hongxun.modules.api.service.BDataDictionaryService;
import com.hongxun.modules.api.service.BEstimateService;
import com.hongxun.modules.api.service.BOtherCostService;
import com.hongxun.modules.api.service.BProjectApplicationService;
import com.hongxun.modules.bss.entity.*;
import com.hongxun.modules.bss.service.*;
import com.hongxun.modules.csg.entity.CPBaseEntity;
import com.hongxun.modules.csg.entity.CScheduleEntity;
import com.hongxun.modules.csg.service.CPBaseService;
import com.hongxun.modules.csg.service.CScheduleService;
import com.hongxun.modules.eys.entity.*;
import com.hongxun.modules.eys.service.*;
import com.hongxun.modules.sys.controller.AbstractController;
import com.hongxun.modules.sys.entity.SysDeptEntity;
import com.hongxun.modules.sys.entity.SysRoleEntity;
import com.hongxun.modules.sys.entity.SysUserEntity;
import com.hongxun.modules.sys.service.*;
import com.lowagie.text.*;
import com.lowagie.text.HeaderFooter;
import com.lowagie.text.pdf.BaseFont;
import com.lowagie.text.rtf.RtfWriter2;
import org.apache.commons.beanutils.BeanUtils;
import org.apache.poi.hssf.usermodel.*;
import org.apache.poi.ss.usermodel.BorderStyle;
import org.apache.poi.ss.usermodel.CellStyle;
import org.apache.poi.ss.usermodel.HorizontalAlignment;
import org.apache.poi.ss.usermodel.VerticalAlignment;
import org.apache.poi.ss.util.CellRangeAddress;
import org.apache.poi.ss.util.RegionUtil;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


/**
 * 项目基础信息表
 *
 * @author zkcn
 * @email youeremail@163.com
 * @date 2018-08-01 15:45:01
 */
@RestController
@RequestMapping("/bss/apbase")
public class APBaseController extends AbstractController {
    @Value("${com.hongxun.IMAGEROTT}")
    private String ROOT;
    @Autowired
    private APBaseService aPBaseService;
    @Autowired
    private BProjectApplicationService bProjectApplicationService;
    @Autowired
    private BEstimateService bEstimateService;
    @Autowired
    private SysUserService sysUserService;
    @Autowired
    private SysRoleDeptService sysRoleDeptService;
    @Autowired
    private SysUserRoleService sysUserRoleService;

    @Autowired
    private APOtherService aPOtherService;
    @Autowired
    private APEstimateService aPEstimateService;
    @Autowired
    private BOtherCostService bOtherCostService;
    @Autowired
    private APCostService aPCostService;
    @Autowired
    private SysDeptService sysDeptService;
    @Autowired
    private APCriteriaService aPCriteriaService;
    @Autowired
    private CPBaseService cPBaseService;
    @Autowired
    private DDeviceBuyService dDeviceBuyService;
    @Autowired
    private DDeviceOldService dDeviceOldService;
    @Autowired
    private BDataDictionaryService bDataDictionaryService;
    @Autowired
    private DMaterialBuyService dMaterialBuyService;
    @Autowired
    private DPictureService dPictureService;
    @Autowired
    private DPointService dPointService;
    @Autowired
    private DCrossCostService dCrossCostService;
    @Autowired
    private EPBaseService ePBaseService;
    @Autowired
    private DDrawLineService dDrawLineService;
    @Autowired
    private APWireService aPWireService;
    @Autowired
    private APRangeService aPRangeService;
    @Autowired
    private EPRangeService ePRangeService;
    @Autowired
    private EPointService ePointService;
    @Autowired
    private EDrawLineService eDrawLineService;
    @Autowired
    private ECrossCostService eCrossCostService;
    @Autowired
    private EPWireService ePWireService;
    @Autowired
    private DWorkContentService dWorkContentService;
    @Autowired
    private DMaterialOldService dMaterialOldService;
    @Autowired
    private EDeviceBuyService eDeviceBuyService;
    @Autowired
    private EDeviceOldService eDeviceOldService;
    @Autowired
    private EMaterialBuyService eMaterialBuyService;
    @Autowired
    private EMaterialOldService eMaterialOldService;
    @Autowired
    private EWorkContentService eWorkContentService;
    @Autowired
    private SysRoleService sysRoleService;
    @Autowired
    private CScheduleService cScheduleService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params) {
        //查询列表数据
        Query query = new Query(params);

        String wheres = " 1=1 ";
        if (query.get("pBType") != null && !query.get("pBType").toString().equals("")) {
            wheres += " and  p_b_Type = '" + query.get("pBType").toString() + "' ";
        }
        if (query.get("pBHive") != null && !query.get("pBHive").toString().equals("")) {
            wheres += " and  p_b_hive = '" + query.get("pBHive").toString() + "' ";
        }
        if (query.get("pBHive") != null && !query.get("pBHive").toString().equals("")) {
            wheres += " and  p_b_hive = '" + query.get("pBHive").toString() + "' ";
        }
        if (query.get("pBState") != null && !query.get("pBState").toString().equals("")) {
            wheres += " and  p_b_state = '" + query.get("pBState").toString() + "' ";
        }
        if (query.get("pBName") != null && !query.get("pBName").toString().equals("")) {
            wheres += " and  p_b_name like '%" + query.get("pBName").toString() + "%' ";
        }
        if (query.get("state") != null && query.get("state").toString().equals("isdelno")) {
            wheres += " and  p_b_datastate != '删除' ";
        }

        boolean myprio = false;
        if (query.get("ourid") != null && query.get("ourid").toString().equals("isok")) {
            List<Long> roleIdList = sysUserRoleService.queryRoleIdList(getUserId());
            String deptId = "";

            for (Long id : roleIdList) {
                SysRoleEntity sysRoleEntity = sysRoleService.queryObject(id);
                if (sysRoleEntity.getRemark().equals("是")) {
                    myprio = true;
                }
                List<Long> deptIdList = sysRoleDeptService.queryDeptIdList(id);
                for (Long sid : deptIdList) {
                    deptId += sid + ",";
                }
            }
            if (deptId.length() > 0) {
                deptId = deptId.substring(0, deptId.length() - 1);
                wheres += " and  p_b_orgid in (" + deptId + ")";
            } else {
                wheres += " and  p_b_orgid in ( -1 )";
            }

        }
        if (!myprio) {
            wheres += "and  FIND_IN_SET('" + getUserId() + "',p_b_collectid)";
        }

        query.put("filterSql", wheres + " ");
        List<APBaseEntity> aPBaseList = aPBaseService.queryList(query);
        List<RequstABaseEntity> aBaseEntities = new ArrayList<>();


        for (APBaseEntity e : aPBaseList) {
            Map<String, Object> map = new HashMap<>();
            Map<String, Object> mapaPOther = new HashMap<>();

            String wheresmy = " 1=1 ";
            wheresmy += " and  p_guid = '" + e.getGuid() + "' ";
            mapaPOther.put("filterSql", wheresmy + " ");
            List<APEstimateEntity> aPEstimateList = aPEstimateService.queryList(mapaPOther);

            //	单线图作图时，只统计单个台区的情况，多个台区时不统计
            String rangeWhere = " 1=1 and p_guid = '" + e.getGuid() + "' ";
            map.put("filterSql", rangeWhere);
            Integer rangeTotal = aPRangeService.queryTotal(map);
            e.setTotalRangeguid(rangeTotal.toString());

            BigDecimal all = BigDecimal.ZERO;
            for (APEstimateEntity aPEstimate : aPEstimateList) {
                if (aPEstimate.getPEFinal() != null) {
                    all = all.add(aPEstimate.getPEFinal());
                }
            }
            RequstABaseEntity r = new RequstABaseEntity();
            try {
                BeanUtils.copyProperties(r, e);
            } catch (IllegalAccessException e1) {
                e1.printStackTrace();
            } catch (InvocationTargetException e1) {
                e1.printStackTrace();
            }

            r.setPriceCount(all.setScale(4, BigDecimal.ROUND_HALF_UP));
            aBaseEntities.add(r);
        }


        int total = aPBaseService.queryTotal(query);

        PageUtils pageUtil = new PageUtils(aBaseEntities, total, query.getLimit(), query.getPage());

        return R.ok().put("page", pageUtil);
    }

    @RequestMapping("/select")
    public R select(@RequestParam Map<String, Object> params) {
        //查询列表数据
        Query query = new Query(params);
        String wheres = " 1=1 ";
        wheres += " and  p_b_datastate != '删除' ";

        boolean myprio = false;
        if (query.get("ourid") != null && query.get("ourid").toString().equals("isok")) {
            List<Long> roleIdList = sysUserRoleService.queryRoleIdList(getUserId());
            String deptId = "";

            for (Long id : roleIdList) {
                SysRoleEntity sysRoleEntity = sysRoleService.queryObject(id);
                if (sysRoleEntity.getRemark().equals("是")) {
                    myprio = true;
                }
                List<Long> deptIdList = sysRoleDeptService.queryDeptIdList(id);
                for (Long sid : deptIdList) {
                    deptId += sid + ",";
                }
            }
            if (deptId.length() > 0) {
                deptId = deptId.substring(0, deptId.length() - 1);
                wheres += " and  p_b_orgid in (" + deptId + ")";
            } else {
                wheres += " and  p_b_orgid in ( -1 )";
            }

        }
        if (!myprio) {
            wheres += "and  FIND_IN_SET('" + getUserId() + "',p_b_collectid)";
        }

        query.put("filterSql", wheres + " ");
        List<APBaseEntity> aPBaseList = aPBaseService.queryList(query);

        return R.ok().put("returnlist", aPBaseList);
    }

    @RequestMapping("/mapselect")
    public R mapselect(@RequestParam Map<String, Object> params) {
        //查询列表数据

        Query query = new Query(params);
        GetOrgPabse(query);
        List<APBaseEntity> aPBaseList = aPBaseService.queryList(query);

        return R.ok().put("returnlist", aPBaseList);
    }

    //节假日修改
    @RequestMapping("/getVdate")
    public R getVdate(@RequestParam Map<String, Object> params) {
        //查询列表数据
        String guid = params.get("guid").toString();
        APBaseEntity aPBase = aPBaseService.queryObject(guid);
        Map<String, Object> mapaPOther = new HashMap<>();

        String mapaPOtherwheres = " 1=1 ";
        mapaPOtherwheres += " and  p_guid = '" + aPBase.getGuid() + "' ";
        mapaPOtherwheres += " and  p_o_datastate != '删除' ";
        mapaPOther.put("filterSql", mapaPOtherwheres + " ");
        List<APOtherEntity> aPOtherList = aPOtherService.queryList(mapaPOther);
        APOtherEntity aPOther = aPOtherList.get(0);
        SysDeptEntity sysDeptEntity = sysDeptService.queryObject(aPBase.getPBOrgid());
        mapaPOther.clear();
        String aPCriteriawheres = " 1=1 ";
        aPCriteriawheres += " and  p_guid = '" + aPBase.getGuid() + "' ";
        aPCriteriawheres += " and  p_c_datastate != '删除' ";
        mapaPOther.put("filterSql", aPCriteriawheres + " ");
        List<APCriteriaEntity> aPCriteriaList = aPCriteriaService.queryList(mapaPOther);
        String aPCriteria1 = "";
        String aPCriteria2 = "";
        String aPCriteria3 = "";
        for (APCriteriaEntity aPCriteriaEntity : aPCriteriaList) {
            if (!aPCriteria1.contains(aPCriteriaEntity.getPCName())) {
                aPCriteria1 += aPCriteriaEntity.getPCName() + "；";
            }
            if (!aPCriteria2.contains(aPCriteriaEntity.getPCChapter())) {
                aPCriteria2 += aPCriteriaEntity.getPCChapter() + "；";
            }
            if (!aPCriteria3.contains(aPCriteriaEntity.getPCCriteria())) {
                aPCriteria3 += aPCriteriaEntity.getPCCriteria() + "";
            }
        }
        mapaPOther.clear();
        String aPEstimatewheres = " 1=1 ";
        aPEstimatewheres += " and  p_guid = '" + aPBase.getGuid() + "' ";
        aPEstimatewheres += " and  p_e_datastate != '删除' ";
        mapaPOther.put("filterSql", aPEstimatewheres + " ");
        List<APEstimateEntity> APEstimateEntitylist = aPEstimateService.queryList(mapaPOther);
        //总费用
        BigDecimal tole = BigDecimal.ZERO;
        //建筑工程费
        BigDecimal tole1 = BigDecimal.ZERO;
        //安装费
        BigDecimal tole2 = BigDecimal.ZERO;
        //购置费
        BigDecimal tole3 = BigDecimal.ZERO;
        //其他费用
        BigDecimal tole4 = BigDecimal.ZERO;
        for (APEstimateEntity aPEstimateEntity : APEstimateEntitylist) {
            BigDecimal tol = aPEstimateEntity.getPEFinal() == null ? BigDecimal.ZERO : aPEstimateEntity.getPEFinal();
            tole = tole.add(tol);

            if (PriceConfig.otherPrice.contains(aPEstimateEntity.getPEItem())) {
                tole4 = tole4.add(tol);
            } else if (PriceConfig.buildPrice.contains(aPEstimateEntity.getPEItem())) {
                tole1 = tole1.add(tol);
            } else if (PriceConfig.buyPrice.contains(aPEstimateEntity.getPEItem())) {
                tole3 = tole3.add(tol);
            } else {
                tole2 = tole2.add(tol);
            }
        }

        mapaPOther.clear();
        String aPCostwheres = " 1=1 ";
        aPCostwheres += " and  p_guid = '" + aPBase.getGuid() + "' ";
        aPCostwheres += " and  p_c_datastate != '删除' ";
        mapaPOther.put("filterSql", aPCostwheres + " ");
        List<APCostEntity> aPCostList = aPCostService.queryList(mapaPOther);
        List<APCostEntityOut> aPCostListOut = new ArrayList<APCostEntityOut>();
        for (APCostEntity aPCostEntity : aPCostList) {
            APCostEntityOut aPCostEntityOut = new APCostEntityOut();
            aPCostEntityOut.setPCNum(aPCostEntity.getPCNum());
            aPCostEntityOut.setPCDetail(aPCostEntity.getPCDetail());
            aPCostEntityOut.setPCExplain(aPCostEntity.getPCExplain());
            aPCostEntityOut.setPCPrice(aPCostEntity.getPCPrice() == null ? "0.00" : aPCostEntity.getPCPrice().toPlainString());
            aPCostEntityOut.setPCRemarks(aPCostEntity.getPCRemarks());
            aPCostListOut.add(aPCostEntityOut);
        }

        mapaPOther.clear();
        String dDeviceOldwheres = " 1=1 ";
        dDeviceOldwheres += " and  p_guid = '" + aPBase.getGuid() + "' ";
        dDeviceOldwheres += " and  d_r_datastate != '删除' ";
        mapaPOther.put("filterSql", dDeviceOldwheres + " ");
        List<DDeviceOldEntity> dDeviceOldList = dDeviceOldService.queryList(mapaPOther);
        List<DDeviceOldEntityOut> dDeviceOldOutList = new ArrayList<DDeviceOldEntityOut>();
        for (DDeviceOldEntity dDeviceOldEntity : dDeviceOldList) {
            DDeviceOldEntityOut dDeviceOldEntityOut = new DDeviceOldEntityOut();
            dDeviceOldEntityOut.setDRName(dDeviceOldEntity.getDRName());
            dDeviceOldEntityOut.setDRFactory(dDeviceOldEntity.getDRFactory());
            dDeviceOldEntityOut.setDRParameter(dDeviceOldEntity.getDRParameter());
            dDeviceOldEntityOut.setDRFactorydate(dDeviceOldEntity.getDRFactorydate() == null ? "" : DateUtils.format(dDeviceOldEntity.getDRFactorydate(), "yyyy-MM-dd"));
            dDeviceOldEntityOut.setDRDeliverydate(dDeviceOldEntity.getDRDeliverydate() == null ? "" : DateUtils.format(dDeviceOldEntity.getDRDeliverydate(), "yyyy-MM-dd"));
            dDeviceOldEntityOut.setDRCode(dDeviceOldEntity.getDRCode());
            dDeviceOldEntityOut.setDRPrice(dDeviceOldEntity.getDRPrice() == null ? "" : dDeviceOldEntity.getDRPrice().toPlainString());
            dDeviceOldEntityOut.setDRNetassets(dDeviceOldEntity.getDRNetassets() == null ? "" : dDeviceOldEntity.getDRNetassets().toPlainString());
            dDeviceOldEntityOut.setDRRate(dDeviceOldEntity.getDRRate() == null ? "" : dDeviceOldEntity.getDRRate().toPlainString());
            dDeviceOldEntityOut.setDRRemovedate(dDeviceOldEntity.getDRRemovedate() == null ? "" : DateUtils.format(dDeviceOldEntity.getDRRemovedate(), "yyyy-MM-dd"));
            if (dDeviceOldEntity.getDROpinion() != null && dDeviceOldEntity.getDROpinion().equals("-9")) {
                dDeviceOldEntityOut.setDROpinion("本项目利用");
            } else {
                dDeviceOldEntityOut.setDROpinion(bDataDictionaryService.selectvaluebykey("opinion_type", dDeviceOldEntity.getDROpinion()));
            }
            dDeviceOldOutList.add(dDeviceOldEntityOut);
        }


        List<DDeviceBuyEntity> dDeviceBuyList = dDeviceBuyService.queryListout(aPBase.getGuid());
        List<BuyEntityOut> dDeviceBuyOutList = new ArrayList<BuyEntityOut>();
        for (DDeviceBuyEntity dDeviceBuyEntity : dDeviceBuyList) {
            BuyEntityOut buyEntityOut = new BuyEntityOut();
            buyEntityOut.setDBMidtype(dDeviceBuyEntity.getDBMidtype());
            buyEntityOut.setDBName(dDeviceBuyEntity.getDBName());
            buyEntityOut.setDBUnit(dDeviceBuyEntity.getDBUnit());
            buyEntityOut.setDBCount(dDeviceBuyEntity.getDBCount() == null ? "0" : dDeviceBuyEntity.getDBCount().toString());
            buyEntityOut.setDBPrice(dDeviceBuyEntity.getDBPrice() == null ? "0.00" : dDeviceBuyEntity.getDBPrice().toPlainString());
            buyEntityOut.setDBPriceall(dDeviceBuyEntity.getDBPriceall() == null ? "0.00" : dDeviceBuyEntity.getDBPriceall().toPlainString());
            dDeviceBuyOutList.add(buyEntityOut);
        }

        List<DMaterialBuyEntity> dMaterialBuyList = dMaterialBuyService.queryListout(aPBase.getGuid());
        List<BuyEntityOut> dMaterialBuyOutList = new ArrayList<BuyEntityOut>();
        for (DMaterialBuyEntity dMaterialBuyEntity : dMaterialBuyList) {
            BuyEntityOut buyEntityOut = new BuyEntityOut();
            buyEntityOut.setDBMidtype(dMaterialBuyEntity.getMBMidtype());
            buyEntityOut.setDBName(dMaterialBuyEntity.getMBName());
            buyEntityOut.setDBUnit(dMaterialBuyEntity.getMBUnit());
            buyEntityOut.setDBCount(dMaterialBuyEntity.getMBCount() == null ? "0" : dMaterialBuyEntity.getMBCount().toString());
            buyEntityOut.setDBPrice(dMaterialBuyEntity.getMBPrice() == null ? "0.00" : dMaterialBuyEntity.getMBPrice().toPlainString());
            buyEntityOut.setDBPriceall(dMaterialBuyEntity.getMBPriceall() == null ? "0.00" : dMaterialBuyEntity.getMBPriceall().toPlainString());
            dMaterialBuyOutList.add(buyEntityOut);
        }


        return R.ok().put("aPBase", aPBase).put("sysDeptEntity", sysDeptEntity).put("aPOther", aPOther)
                .put("aPCriteria2", aPCriteria2).put("aPCriteria1", aPCriteria1).put("aPCriteria3", aPCriteria3)
                .put("dDeviceOldList", dDeviceOldOutList).put("tole", tole.toPlainString()).put("tole1", tole1.toPlainString())
                .put("tole2", tole2.toPlainString()).put("tole3", tole3.toPlainString()).put("tole4", tole4.toPlainString())
                .put("dMaterialBuyList", dMaterialBuyOutList).put("dDeviceBuyList", dDeviceBuyOutList).put("aPCostList", aPCostListOut);
    }

    @RequestMapping("/fjlist")
    public R fjlist(@RequestParam Map<String, Object> params) {
        //查询列表数据
        Query query = new Query(params);


        List<FJEntity> fJEntityList = new ArrayList<>();
        FJEntity fJEntity1 = new FJEntity();
        fJEntity1.setGuid("fj1");
        fJEntity1.setFName("申请书");
        FJEntity fJEntity2 = new FJEntity();
        fJEntity2.setGuid("fj2");
        fJEntity2.setFName("设备材料购置表");
        FJEntity fJEntity3 = new FJEntity();
        fJEntity3.setGuid("fj3");
        fJEntity3.setFName("设备材料拆除表");
        FJEntity fJEntity4 = new FJEntity();
        fJEntity4.setGuid("fj4");
        fJEntity4.setFName("点位设备材料明细表");
        FJEntity fJEntity5 = new FJEntity();
        fJEntity5.setGuid("fj5");
        fJEntity5.setFName("设备材料汇总表");
        FJEntity fJEntity6 = new FJEntity();
        fJEntity6.setGuid("fj6");
        fJEntity6.setFName("点位照片表");
        fJEntityList.add(fJEntity1);
        fJEntityList.add(fJEntity2);
        fJEntityList.add(fJEntity3);
        fJEntityList.add(fJEntity4);
        fJEntityList.add(fJEntity5);
        fJEntityList.add(fJEntity6);

        int total = fJEntityList.size();

        PageUtils pageUtil = new PageUtils(fJEntityList, total, query.getLimit(), query.getPage());

        return R.ok().put("page", pageUtil);
    }

    //踏勘人员待办项目列表
    @RequestMapping("/tkdbxmlist")
    public R tkdbxmlist(@RequestParam Map<String, Object> params) {
        //查询列表数据
        Query query = new Query(params);
        String wheres = " 1=1 ";
        wheres += " and  p_b_datastate != '删除' ";
        wheres += "and  FIND_IN_SET('" + getUserId() + "',p_b_collectid)";
        if (query.get("pBType") != null && !query.get("pBType").toString().equals("")) {
            wheres += " and  p_b_category = '" + query.get("pBType").toString() + "' ";
        }
        if (query.get("pBState") != null && !query.get("pBState").toString().equals("")) {
            wheres += " and  p_operation_state = '" + query.get("pBState").toString() + "' ";
        } else {
            wheres += " and  p_operation_state in ('101','102','105') ";
        }
        if (query.get("pBName") != null && !query.get("pBName").toString().equals("")) {
            wheres += " and  p_b_name like '%" + query.get("pBName").toString() + "%' ";
        }

        query.put("filterSql", wheres + " ");
        List<APBaseEntity> aPBaseList = aPBaseService.queryList(query);
        int total = aPBaseService.queryTotal(query);

        PageUtils pageUtil = new PageUtils(aPBaseList, total, query.getLimit(), query.getPage());

        return R.ok().put("page", pageUtil);
    }

    //踏勘人员踏勘项目列表
    @RequestMapping("/tktkxmlist")
    public R tktkxmlist(@RequestParam Map<String, Object> params) {
        //查询列表数据
        Query query = new Query(params);
        String wheres = " 1=1 ";
        wheres += " and  p_b_datastate != '删除' ";
        wheres += "and  FIND_IN_SET('" + getUserId() + "',p_b_collectid)";
        if (query.get("pBType") != null && !query.get("pBType").toString().equals("")) {
            wheres += " and  p_b_category = '" + query.get("pBType").toString() + "' ";
        }
        if (query.get("pBState") != null && !query.get("pBState").toString().equals("")) {
            wheres += " and  p_operation_state = '" + query.get("pBState").toString() + "' ";
        } else {
            wheres += " and  p_operation_state in ('103','105') ";
        }
        if (query.get("pBName") != null && !query.get("pBName").toString().equals("")) {
            wheres += " and  p_b_name like '%" + query.get("pBName").toString() + "%' ";
        }

        query.put("filterSql", wheres + " ");
        List<APBaseEntity> aPBaseList = aPBaseService.queryList(query);
        int total = aPBaseService.queryTotal(query);

        PageUtils pageUtil = new PageUtils(aPBaseList, total, query.getLimit(), query.getPage());

        return R.ok().put("page", pageUtil);
    }

    //踏勘人员待审核项目列表
    @RequestMapping("/tkdsxmlist")
    public R tkdsxmlist(@RequestParam Map<String, Object> params) {
        //查询列表数据
        Query query = new Query(params);
        String wheres = " 1=1 ";
        wheres += " and  p_b_datastate != '删除' ";
        wheres += "and  FIND_IN_SET('" + getUserId() + "',p_b_collectid)";
        if (query.get("pBType") != null && !query.get("pBType").toString().equals("")) {
            wheres += " and  p_b_category = '" + query.get("pBType").toString() + "' ";
        }
        if (query.get("pBState") != null && !query.get("pBState").toString().equals("")) {
            wheres += " and  p_operation_state = '" + query.get("pBState").toString() + "' ";
        } else {
            wheres += " and  p_operation_state in ('104') ";
        }
        if (query.get("pBName") != null && !query.get("pBName").toString().equals("")) {
            wheres += " and  p_b_name like '%" + query.get("pBName").toString() + "%' ";
        }

        query.put("filterSql", wheres + " ");
        List<APBaseEntity> aPBaseList = aPBaseService.queryList(query);
        int total = aPBaseService.queryTotal(query);

        PageUtils pageUtil = new PageUtils(aPBaseList, total, query.getLimit(), query.getPage());

        return R.ok().put("page", pageUtil);
    }

    //踏勘人员储备项目列表
    @RequestMapping("/tkcbxmlist")
    public R tkcbxmlist(@RequestParam Map<String, Object> params) {
        //查询列表数据
        Query query = new Query(params);
        String wheres = " 1=1 ";
        wheres += " and  p_b_datastate != '删除' ";
        wheres += "and  FIND_IN_SET('" + getUserId() + "',p_b_collectid)";
        if (query.get("pBType") != null && !query.get("pBType").toString().equals("")) {
            wheres += " and  p_b_category = '" + query.get("pBType").toString() + "' ";
        }
        if (query.get("pBState") != null && !query.get("pBState").toString().equals("")) {
            wheres += " and  p_operation_state = '" + query.get("pBState").toString() + "' ";
        } else {
            wheres += " and  p_operation_state in ('106') ";
        }
        if (query.get("pBName") != null && !query.get("pBName").toString().equals("")) {
            wheres += " and  p_b_name like '%" + query.get("pBName").toString() + "%' ";
        }

        query.put("filterSql", wheres + " ");
        List<APBaseEntity> aPBaseList = aPBaseService.queryList(query);
        int total = aPBaseService.queryTotal(query);

        PageUtils pageUtil = new PageUtils(aPBaseList, total, query.getLimit(), query.getPage());

        return R.ok().put("page", pageUtil);
    }

    //踏勘人下载手机文件列表
    @RequestMapping("/tkxzxmlist")
    public R tkxzxmlist(@RequestParam Map<String, Object> params) {
        //查询列表数据
        Query query = new Query(params);
        String wheres = " 1=1 ";
        wheres += " and  p_b_datastate != '删除' ";
        wheres += "and  FIND_IN_SET('" + getUserId() + "',p_b_collectid)";
        if (query.get("pBType") != null && !query.get("pBType").toString().equals("")) {
            wheres += " and  p_b_category = '" + query.get("pBType").toString() + "' ";
        }
        if (query.get("pBState") != null && !query.get("pBState").toString().equals("")) {
            wheres += " and  p_operation_state = '" + query.get("pBState").toString() + "' ";
        } else {
            wheres += " and  p_operation_state in ('101','102','103','105') ";
        }
        if (query.get("pBName") != null && !query.get("pBName").toString().equals("")) {
            wheres += " and  p_b_name like '%" + query.get("pBName").toString() + "%' ";
        }

        query.put("filterSql", wheres + " ");
        List<APBaseEntity> aPBaseList = aPBaseService.queryList(query);
        int total = aPBaseService.queryTotal(query);

        PageUtils pageUtil = new PageUtils(aPBaseList, total, query.getLimit(), query.getPage());

        return R.ok().put("page", pageUtil);
    }

    //审核人员待办项目列表
    @RequestMapping("/shdbxmlist")
    public R shdbxmlist(@RequestParam Map<String, Object> params) {
        //查询列表数据
        Query query = new Query(params);
        String wheres = " 1=1 ";
        wheres += " and  p_b_datastate != '删除' ";

        if (query.get("pBType") != null && !query.get("pBType").toString().equals("")) {
            wheres += " and  p_b_category = '" + query.get("pBType").toString() + "' ";
        }
        if (query.get("pBState") != null && !query.get("pBState").toString().equals("")) {
            wheres += " and  p_operation_state = '" + query.get("pBState").toString() + "' ";
        } else {
            wheres += " and  p_operation_state in ('104') ";
        }
        if (query.get("pBName") != null && !query.get("pBName").toString().equals("")) {
            wheres += " and  p_b_name like '%" + query.get("pBName").toString() + "%' ";
        }
        if (query.get("pBOrg") != null && !query.get("pBOrg").toString().equals("")) {
            wheres += " and  p_b_orgid = '" + query.get("pBOrg").toString() + "' ";
        } else {
            List<Long> deptIds = sysDeptService.queryDetpIdListByUser(getUserId());
            String deptId = "";
            for (Long ids : deptIds) {
                deptId += ids + ",";
            }
            if (deptId.length() > 0) {
                deptId = deptId.substring(0, deptId.length() - 1);
                wheres += " and  p_b_orgid in (" + deptId + ")";
            } else {
                wheres += " and  p_b_orgid in ( -1 )";
            }

        }


        query.put("filterSql", wheres + " ");
        List<APBaseEntity> aPBaseList = aPBaseService.queryList(query);
        int total = aPBaseService.queryTotal(query);

        PageUtils pageUtil = new PageUtils(aPBaseList, total, query.getLimit(), query.getPage());

        return R.ok().put("page", pageUtil);
    }

    //审核人员踏勘项目列表
    @RequestMapping("/shtkxmlist")
    public R shtkxmlist(@RequestParam Map<String, Object> params) {
        //查询列表数据
        Query query = new Query(params);
        String wheres = " 1=1 ";
        wheres += " and  p_b_datastate != '删除' ";

        if (query.get("pBType") != null && !query.get("pBType").toString().equals("")) {
            wheres += " and  p_b_category = '" + query.get("pBType").toString() + "' ";
        }
        if (query.get("pBState") != null && !query.get("pBState").toString().equals("")) {
            wheres += " and  p_operation_state = '" + query.get("pBState").toString() + "' ";
        } else {
            wheres += " and  p_operation_state in ('101','102','103','105') ";
        }
        if (query.get("pBName") != null && !query.get("pBName").toString().equals("")) {
            wheres += " and  p_b_name like '%" + query.get("pBName").toString() + "%' ";
        }
        if (query.get("pBOrg") != null && !query.get("pBOrg").toString().equals("")) {
            wheres += " and  p_b_orgid = '" + query.get("pBOrg").toString() + "' ";
        } else {
            List<Long> deptIds = sysDeptService.queryDetpIdListByUser(getUserId());
            String deptId = "";
            for (Long ids : deptIds) {
                deptId += ids + ",";
            }
            if (deptId.length() > 0) {
                deptId = deptId.substring(0, deptId.length() - 1);
                wheres += " and  p_b_orgid in (" + deptId + ")";
            } else {
                wheres += " and  p_b_orgid in ( -1 )";
            }

        }


        query.put("filterSql", wheres + " ");
        List<APBaseEntity> aPBaseList = aPBaseService.queryList(query);
        int total = aPBaseService.queryTotal(query);

        PageUtils pageUtil = new PageUtils(aPBaseList, total, query.getLimit(), query.getPage());

        return R.ok().put("page", pageUtil);
    }

    //审核人员踏勘项目列表
    @RequestMapping("/shgdxmlist")
    public R shgdxmlist(@RequestParam Map<String, Object> params) {
        //查询列表数据
        Query query = new Query(params);
        String wheres = " 1=1 ";
        wheres += " and  p_b_datastate != '删除' ";

        if (query.get("pBType") != null && !query.get("pBType").toString().equals("")) {
            wheres += " and  p_b_category = '" + query.get("pBType").toString() + "' ";
        }
        if (query.get("pBState") != null && !query.get("pBState").toString().equals("")) {
            wheres += " and  p_operation_state = '" + query.get("pBState").toString() + "' ";
        } else {
            wheres += " and  p_operation_state in ('106') ";
        }
        if (query.get("pBName") != null && !query.get("pBName").toString().equals("")) {
            wheres += " and  p_b_name like '%" + query.get("pBName").toString() + "%' ";
        }
        if (query.get("pBOrg") != null && !query.get("pBOrg").toString().equals("")) {
            wheres += " and  p_b_orgid = '" + query.get("pBOrg").toString() + "' ";
        } else {
            List<Long> deptIds = sysDeptService.queryDetpIdListByUser(getUserId());
            String deptId = "";
            for (Long ids : deptIds) {
                deptId += ids + ",";
            }
            if (deptId.length() > 0) {
                deptId = deptId.substring(0, deptId.length() - 1);
                wheres += " and  p_b_orgid in (" + deptId + ")";
            } else {
                wheres += " and  p_b_orgid in ( -1 )";
            }

        }


        query.put("filterSql", wheres + " ");
        List<APBaseEntity> aPBaseList = aPBaseService.queryList(query);
        int total = aPBaseService.queryTotal(query);

        PageUtils pageUtil = new PageUtils(aPBaseList, total, query.getLimit(), query.getPage());

        return R.ok().put("page", pageUtil);
    }

    private void GetOrgPabse(Query query) {
        String wheres = " 1=1 ";
        wheres += " and  p_b_datastate != '删除' ";
        if (query.get("ourid") != null && query.get("ourid").toString().equals("isok")) {
            List<Long> deptIds = sysDeptService.queryDetpIdListByUser(getUserId());
            String deptId = "";
            for (Long ids : deptIds) {
                deptId += ids + ",";
            }
            if (deptId.length() > 0) {
                deptId = deptId.substring(0, deptId.length() - 1);
                wheres += " and  p_b_orgid in (" + deptId + ")";
            } else {
                wheres += " and  p_b_orgid in ( -1 )";
            }


        }
        if (query.get("operation") != null) {
            wheres += " and  p_operation_state = '" + query.get("operation").toString() + "'";
        }
        query.put("filterSql", wheres + " ");
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{guid}")
    public R info(@PathVariable("guid") String guid) {
        APBaseEntity aPBase = aPBaseService.queryObject(guid);
        List<SysUserEntity> userListaa = sysUserService.queryListBydeptid(aPBase.getPBOrgid());
        return R.ok().put("aPBase", aPBase).put("userallmy", userListaa);
    }


    /**
     * 点位照片表
     *
     * @param request
     * @param response
     * @throws IOException
     * @throws DocumentException
     */
    @RequestMapping("/exportsimg")
    public void exportsimg(HttpServletRequest request, HttpServletResponse response) throws IOException, DocumentException {
        String guid = request.getParameter("guid");
        APBaseEntity aPBase = aPBaseService.queryObject(guid);

        response.setContentType("application/msword;charset=utf-8");
        try {
            response.setHeader("Content-Disposition", "attachment;filename=" + new String(((aPBase.getPBName() == null ? "" : aPBase.getPBName()) + "项目照片.doc").getBytes(), "iso-8859-1"));
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }

        Document document = new Document();
        BaseFont bfChinese = BaseFont.createFont("C:/WINDOWS/Fonts/SIMSUN.TTC,1", BaseFont.IDENTITY_H, BaseFont.EMBEDDED);

        RtfWriter2.getInstance(document, response.getOutputStream());
        Font titleFontye = new Font(bfChinese, 8, Font.BOLD);
        HeaderFooter footer = new HeaderFooter(new Phrase("页码：", titleFontye), true);
        footer.setAlignment(1);
        footer.setBorder(Rectangle.NO_BORDER);

        document.setFooter(footer);
        document.open();
        setexportsimg(document, bfChinese, aPBase);

        document.close();


    }


    //	点位照片表
    public void setexportsimg(Document document, BaseFont bfChinese, APBaseEntity aPBase) throws DocumentException, IOException {

        //表题字体
        Font titleFont = new Font(bfChinese, 11, Font.BOLD);
        //表格字体
        Font contextFont = new Font(bfChinese, 8, Font.NORMAL);
        // 签字字体
        Font qinFont = new Font(bfChinese, 10, Font.NORMAL);
        Paragraph title = new Paragraph((aPBase.getPBName() == null ? "" : aPBase.getPBName()) + "项目照片");
        title.setAlignment(Element.ALIGN_CENTER);
        title.setFont(titleFont);
        document.add(title);


        Map<String, Object> mapapole = new HashMap<>();
        String polewheres = " 1=1 ";
        polewheres += " and  p_guid = '" + aPBase.getGuid() + "' ";
        polewheres += " and  p_p_datastate!= '删除' ";
        mapapole.put("filterSql", polewheres + " order by p_r_guid,   CONVERT(Right(p_p_code,LENGTH(p_p_code)-instr(p_p_code, '#')) ,SIGNED) asc ");
        List<DPointEntity> dPointList = dPointService.queryList(mapapole);

        Map<String, Object> mapCost = new HashMap<>();
        String mapCostwheres = " 1=1 ";
        mapCostwheres += " and  p_guid = '" + aPBase.getGuid() + "' ";
        mapCostwheres += " and  c_c_datastate!= '删除' ";
        mapCost.put("filterSql", mapCostwheres + " ");
        List<DCrossCostEntity> dCrossCostList = dCrossCostService.queryList(mapCost);

        addpoleimg(document, aPBase, contextFont, dPointList);
        addcrossimg(document, aPBase, contextFont, dCrossCostList);

    }

    private void addcrossimg(Document document, APBaseEntity aPBase, Font contextFont, List<DCrossCostEntity> dCrossCostList) throws DocumentException, IOException {
        for (DCrossCostEntity dCrossCostEntity : dCrossCostList) {
            Map<String, Object> mapaPOther = new HashMap<>();
            String mapaPOtherwheres = " 1=1 ";
            mapaPOtherwheres += " and  p_guid = '" + aPBase.getGuid() + "' ";
            mapaPOtherwheres += " and  p_status = '储备' ";
            mapaPOtherwheres += " and  p_p_guid = '" + dCrossCostEntity.getGuid().toString() + "' ";
            mapaPOtherwheres += " and  p_datastate != '删除' ";
            mapaPOther.put("filterSql", mapaPOtherwheres + " ");
            List<DPictureEntity> dPictureList = dPictureService.queryList(mapaPOther);
//			document.setMargins(40F,40F,50F,90F);	//	文档边距
            document.setMargins(40F, 40F, 20F, 73F);    //	文档边距
            if (dPictureList.size() > 0) {

                Table table = new Table(6);
                int[] withs = {1, 2, 1, 2, 1, 2};
                table.setWidths(withs);
                /** 表格所占页面宽度 author:yyli Sep 15, 2010 */
                table.setWidth(90);
                /** 居中显示 author:yyli Sep 15, 2010 */
                table.setAlignment(Element.ALIGN_CENTER);
                /** 自动填满 author:yyli Sep 15, 2010 */
                table.setAutoFillEmptyCells(true);
                APRangeEntity aPRangeEntity = aPRangeService.queryObject(dCrossCostEntity.getPRGuid());

                OutPutUtils.addcell(table, bDataDictionaryService.selectvaluebykey("cross_type", dCrossCostEntity.getCType()) + "(" + aPRangeEntity.getPRName() + "_" + dCrossCostEntity.getCCName() + ")", 0, 6, true, contextFont);
                //	一个点位最多显示3张照片
                int chushu = 1;
                /*int chishu = dPictureList.size() / 3;
				int yushu = dPictureList.size() % 3;

				if (yushu > 0) {
					chishu = chishu + 1;
				}*/
                for (int i = 0; i < chushu; i++) {
                    boolean one = false;
                    boolean two = false;
                    boolean three = false;

                    if ((3 * i) < dPictureList.size()) {
                        one = true;
                    }
                    if (((3 * i) + 1) < dPictureList.size()) {
                        two = true;
                    }
                    if (((3 * i) + 2) < dPictureList.size()) {
                        three = true;
                    }
                    if (one) {
                        File file = new File(ROOT + dPictureList.get(3 * i).getPServeraddress());
                        if (file.exists()) {
                            OutPutUtils.addcellimg(table, ROOT + dPictureList.get(3 * i).getPServeraddress(), 8, 2, true, contextFont);
                        } else {
                            OutPutUtils.addcell(table, "没找到照片", 8, 2, true, contextFont);

                        }
                    } else {
                        OutPutUtils.addcell(table, "", 8, 2, true, contextFont);
                    }
                    if (two) {
                        File file = new File(ROOT + dPictureList.get((3 * i) + 1).getPServeraddress());
                        if (file.exists()) {
                            OutPutUtils.addcellimg(table, ROOT + dPictureList.get((3 * i) + 1).getPServeraddress(), 8, 2, true, contextFont);
                        } else {
                            OutPutUtils.addcell(table, "没找到照片", 8, 2, true, contextFont);

                        }
                    } else {
                        OutPutUtils.addcell(table, "", 8, 2, true, contextFont);
                    }
                    if (three) {
                        File file = new File(ROOT + dPictureList.get((3 * i) + 2).getPServeraddress());
                        if (file.exists()) {
                            OutPutUtils.addcellimg(table, ROOT + dPictureList.get((3 * i) + 2).getPServeraddress(), 8, 2, true, contextFont);
                        } else {
                            OutPutUtils.addcell(table, "没找到照片", 8, 2, true, contextFont);

                        }
                    } else {
                        OutPutUtils.addcell(table, "", 8, 2, true, contextFont);
                    }


                    OutPutUtils.addcell(table, "名称", 0, 0, true, contextFont);
                    if (one) {
                        OutPutUtils.addcell(table, dPictureList.get(3 * i).getPLabel(), 0, 0, true, contextFont);
                    } else {
                        OutPutUtils.addcell(table, "", 0, 0, true, contextFont);
                    }
                    OutPutUtils.addcell(table, "名称", 0, 0, true, contextFont);
                    if (two) {
                        OutPutUtils.addcell(table, dPictureList.get((3 * i) + 1).getPLabel(), 0, 0, true, contextFont);
                    } else {
                        OutPutUtils.addcell(table, "", 0, 0, true, contextFont);
                    }
                    OutPutUtils.addcell(table, "名称", 0, 0, true, contextFont);
                    if (three) {
                        OutPutUtils.addcell(table, dPictureList.get((3 * i) + 2).getPLabel(), 0, 0, true, contextFont);
                    } else {
                        OutPutUtils.addcell(table, "", 0, 0, true, contextFont);
                    }

                    OutPutUtils.addcell(table, "来源", 0, 0, true, contextFont);
                    if (one) {
                        OutPutUtils.addcell(table, dPictureList.get(3 * i).getPPResour(), 0, 0, true, contextFont);
                    } else {
                        OutPutUtils.addcell(table, "", 0, 0, true, contextFont);
                    }
                    OutPutUtils.addcell(table, "来源", 0, 0, true, contextFont);
                    if (two) {
                        OutPutUtils.addcell(table, dPictureList.get((3 * i) + 1).getPPResour(), 0, 0, true, contextFont);
                    } else {
                        OutPutUtils.addcell(table, "", 0, 0, true, contextFont);
                    }
                    OutPutUtils.addcell(table, "来源", 0, 0, true, contextFont);
                    if (three) {
                        OutPutUtils.addcell(table, dPictureList.get((3 * i) + 2).getPPResour(), 0, 0, true, contextFont);
                    } else {
                        OutPutUtils.addcell(table, "", 0, 0, true, contextFont);
                    }
                    OutPutUtils.addcell(table, "时间", 0, 0, true, contextFont);
                    if (one) {
                        OutPutUtils.addcell(table, dPictureList.get(3 * i).getPTime() == null ? "" : DateUtils.format(dPictureList.get(3 * i).getPTime(), "yyyy-MM-dd"), 0, 0, true, contextFont);
                    } else {
                        OutPutUtils.addcell(table, "", 0, 0, true, contextFont);
                    }
                    OutPutUtils.addcell(table, "时间", 0, 0, true, contextFont);
                    if (two) {
                        OutPutUtils.addcell(table, dPictureList.get((3 * i) + 1).getPTime() == null ? "" : DateUtils.format(dPictureList.get((3 * i) + 1).getPTime(), "yyyy-MM-dd"), 0, 0, true, contextFont);
                    } else {
                        OutPutUtils.addcell(table, "", 0, 0, true, contextFont);
                    }
                    OutPutUtils.addcell(table, "时间", 0, 0, true, contextFont);
                    if (three) {
                        OutPutUtils.addcell(table, dPictureList.get((3 * i) + 2).getPTime() == null ? "" : DateUtils.format(dPictureList.get((3 * i) + 2).getPTime(), "yyyy-MM-dd"), 0, 0, true, contextFont);
                    } else {
                        OutPutUtils.addcell(table, "", 0, 0, true, contextFont);
                    }


                }

                Paragraph nuss = new Paragraph("");    //	表与表之间加空行（调整格式）
                document.add(nuss);
                document.add(table);
            }
        }
    }

    private void addpoleimg(Document document, APBaseEntity aPBase, Font contextFont, List<DPointEntity> dPointList) throws DocumentException, IOException {
        for (DPointEntity dPointEntity : dPointList) {
            Map<String, Object> mapaPOther = new HashMap<>();
            String mapaPOtherwheres = " 1=1 ";
            mapaPOtherwheres += " and  p_guid = '" + aPBase.getGuid() + "' ";
            mapaPOtherwheres += " and  p_status = '储备' ";
            mapaPOtherwheres += " and  p_p_guid = '" + dPointEntity.getGuid().toString() + "' ";
            mapaPOtherwheres += " and  p_datastate != '删除' ";
            mapaPOther.put("filterSql", mapaPOtherwheres + " ");
            List<DPictureEntity> dPictureList = dPictureService.queryList(mapaPOther);
            document.setMargins(40F, 40F, 20F, 73F);    //	文档边距
            if (dPictureList.size() > 0) {

                Table table = new Table(6);
                int[] withs = {1, 2, 1, 2, 1, 2};
                table.setWidths(withs);
                /** 表格所占页面宽度 author:yyli Sep 15, 2010 */
                table.setWidth(90);

                /** 居中显示 author:yyli Sep 15, 2010 */
                table.setAlignment(Element.ALIGN_CENTER);
                /** 自动填满 author:yyli Sep 15, 2010 */
                table.setAutoFillEmptyCells(true);
                APRangeEntity aPRangeEntity = aPRangeService.queryObject(dPointEntity.getPRGuid());

                OutPutUtils.addcell(table, dPointEntity.getPPCode() + "(" + aPRangeEntity.getPRName() + "_" + dPointEntity.getPPName() + ")", 0, 6, true, contextFont);

                //	一个点位设定最多显示3张照片
				/*int chishu = dPictureList.size() / 3;
				int yushu = dPictureList.size() % 3;

				if (yushu > 0) {
					chishu = chishu + 1;
				}*/

                int chushu = 1;
                for (int i = 0; i < chushu; i++) {
                    boolean one = false;
                    boolean two = false;
                    boolean three = false;

                    if ((3 * i) < dPictureList.size()) {
                        one = true;
                    }
                    if (((3 * i) + 1) < dPictureList.size()) {
                        two = true;
                    }
                    if (((3 * i) + 2) < dPictureList.size()) {
                        three = true;
                    }
                    if (one) {
                        File file = new File(ROOT + dPictureList.get(3 * i).getPServeraddress());
                        if (file.exists()) {
                            OutPutUtils.addcellimg(table, ROOT + dPictureList.get(3 * i).getPServeraddress(), 8, 2, true, contextFont);
                        } else {
                            OutPutUtils.addcell(table, "没找到照片", 8, 2, true, contextFont);

                        }
                    } else {
                        OutPutUtils.addcell(table, "", 8, 2, true, contextFont);
                    }
                    if (two) {
                        File file = new File(ROOT + dPictureList.get((3 * i) + 1).getPServeraddress());
                        if (file.exists()) {
                            OutPutUtils.addcellimg(table, ROOT + dPictureList.get((3 * i) + 1).getPServeraddress(), 8, 2, true, contextFont);
                        } else {
                            OutPutUtils.addcell(table, "没找到照片", 8, 2, true, contextFont);

                        }
                    } else {
                        OutPutUtils.addcell(table, "", 8, 2, true, contextFont);
                    }
                    if (three) {
                        File file = new File(ROOT + dPictureList.get((3 * i) + 2).getPServeraddress());
                        if (file.exists()) {
                            OutPutUtils.addcellimg(table, ROOT + dPictureList.get((3 * i) + 2).getPServeraddress(), 8, 2, true, contextFont);
                        } else {
                            OutPutUtils.addcell(table, "没找到照片", 8, 2, true, contextFont);

                        }
                    } else {
                        OutPutUtils.addcell(table, "", 8, 2, true, contextFont);
                    }


                    OutPutUtils.addcell(table, "名称", 0, 0, true, contextFont);
                    if (one) {
                        OutPutUtils.addcell(table, dPictureList.get(3 * i).getPLabel(), 0, 0, true, contextFont);
                    } else {
                        OutPutUtils.addcell(table, "", 0, 0, true, contextFont);
                    }
                    OutPutUtils.addcell(table, "名称", 0, 0, true, contextFont);
                    if (two) {
                        OutPutUtils.addcell(table, dPictureList.get((3 * i) + 1).getPLabel(), 0, 0, true, contextFont);
                    } else {
                        OutPutUtils.addcell(table, "", 0, 0, true, contextFont);
                    }
                    OutPutUtils.addcell(table, "名称", 0, 0, true, contextFont);
                    if (three) {
                        OutPutUtils.addcell(table, dPictureList.get((3 * i) + 2).getPLabel(), 0, 0, true, contextFont);
                    } else {
                        OutPutUtils.addcell(table, "", 0, 0, true, contextFont);
                    }

                    OutPutUtils.addcell(table, "来源", 0, 0, true, contextFont);
                    if (one) {
                        OutPutUtils.addcell(table, dPictureList.get(3 * i).getPPResour(), 0, 0, true, contextFont);
                    } else {
                        OutPutUtils.addcell(table, "", 0, 0, true, contextFont);
                    }
                    OutPutUtils.addcell(table, "来源", 0, 0, true, contextFont);
                    if (two) {
                        OutPutUtils.addcell(table, dPictureList.get((3 * i) + 1).getPPResour(), 0, 0, true, contextFont);
                    } else {
                        OutPutUtils.addcell(table, "", 0, 0, true, contextFont);
                    }
                    OutPutUtils.addcell(table, "来源", 0, 0, true, contextFont);
                    if (three) {
                        OutPutUtils.addcell(table, dPictureList.get((3 * i) + 2).getPPResour(), 0, 0, true, contextFont);
                    } else {
                        OutPutUtils.addcell(table, "", 0, 0, true, contextFont);
                    }

                    OutPutUtils.addcell(table, "时间", 0, 0, true, contextFont);
                    if (one) {
                        OutPutUtils.addcell(table, dPictureList.get(3 * i).getPTime() == null ? "" : DateUtils.format(dPictureList.get(3 * i).getPTime(), "yyyy-MM-dd"), 0, 0, true, contextFont);
                    } else {
                        OutPutUtils.addcell(table, "", 0, 0, true, contextFont);
                    }
                    OutPutUtils.addcell(table, "时间", 0, 0, true, contextFont);
                    if (two) {
                        OutPutUtils.addcell(table, dPictureList.get((3 * i) + 1).getPTime() == null ? "" : DateUtils.format(dPictureList.get((3 * i) + 1).getPTime(), "yyyy-MM-dd"), 0, 0, true, contextFont);
                    } else {
                        OutPutUtils.addcell(table, "", 0, 0, true, contextFont);
                    }
                    OutPutUtils.addcell(table, "时间", 0, 0, true, contextFont);
                    if (three) {
                        OutPutUtils.addcell(table, dPictureList.get((3 * i) + 2).getPTime() == null ? "" : DateUtils.format(dPictureList.get((3 * i) + 2).getPTime(), "yyyy-MM-dd"), 0, 0, true, contextFont);
                    } else {
                        OutPutUtils.addcell(table, "", 0, 0, true, contextFont);
                    }

                }
                Paragraph nuss = new Paragraph("");    //	表与表之间加空行（调整格式）
                document.add(nuss);
                document.add(table);
            }
        }
    }


    /**
     * 申请书
     *
     * @param request
     * @param response
     * @throws IOException
     * @throws DocumentException
     */
    @RequestMapping("/exports")
    public void exports(HttpServletRequest request, HttpServletResponse response) throws IOException, DocumentException {
        String guid = request.getParameter("guid");
        APBaseEntity aPBase = aPBaseService.queryObject(guid);

        response.setContentType("application/msword;charset=utf-8");
        try {
            response.setHeader("Content-Disposition", "attachment;filename=" + new String(((aPBase.getPBBookname() == null ? "项目申请书" : aPBase.getPBBookname()) + ".doc").getBytes(), "iso-8859-1"));
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }

        Document document = new Document(PageSize.A4.rotate());
        BaseFont bfChinese = BaseFont.createFont("C:/WINDOWS/Fonts/SIMSUN.TTC,1", BaseFont.IDENTITY_H, BaseFont.EMBEDDED);

        RtfWriter2.getInstance(document, response.getOutputStream());
        Font titleFontye = new Font(bfChinese, 8, Font.BOLD);
        HeaderFooter footer = new HeaderFooter(new Phrase("页码：", titleFontye), true);
        footer.setAlignment(1);
        footer.setBorder(Rectangle.NO_BORDER);
        document.setFooter(footer);
        document.open();
        setexports(document, bfChinese, aPBase);

        document.close();

    }

    /**
     * 材料汇总表
     *
     * @param request
     * @param response
     * @throws IOException
     * @throws DocumentException
     */
    @RequestMapping("/exportsbyhz")
    public void exportsbyhz(HttpServletRequest request, HttpServletResponse response) throws IOException, DocumentException {
        String guid = request.getParameter("guid");
        APBaseEntity aPBase = aPBaseService.queryObject(guid);
        List<DMaterialBuyEntity> dMaterialBuyList = dMaterialBuyService.queryListhz(aPBase.getGuid());
        List<DDeviceBuyEntity> dDeviceBuyList = dDeviceBuyService.queryListhz(aPBase.getGuid());


        String[] title = {"类别", "名称", "单位", "数量", "价格"};
        String fileName = aPBase.getPBName() + "材料设备汇总表" + System.currentTimeMillis() + ".xls";
        String sheetName = "材料设备汇总表";
        String[][] content = new String[dMaterialBuyList.size() + dDeviceBuyList.size()][title.length];
        for (int i = 0; i < dDeviceBuyList.size(); i++) {

            content[i][0] = dDeviceBuyList.get(i).getMbanktype();
            content[i][1] = dDeviceBuyList.get(i).getDBMidtype();
            content[i][2] = dDeviceBuyList.get(i).getDBUnit();
            content[i][3] = dDeviceBuyList.get(i).getDBCount() == null ? "0.00" : dDeviceBuyList.get(i).getDBCount().toString();
            content[i][4] = dDeviceBuyList.get(i).getDBPriceall() == null ? "0.00" : dDeviceBuyList.get(i).getDBPriceall().toPlainString();
        }
        for (int i = 0; i < dMaterialBuyList.size(); i++) {

            content[dDeviceBuyList.size() +i][0] = dMaterialBuyList.get(i).getMbanktype();
            content[dDeviceBuyList.size() +i][1] = dMaterialBuyList.get(i).getMBMidtype();
            content[dDeviceBuyList.size() +i][2] = dMaterialBuyList.get(i).getMBUnit();
            content[dDeviceBuyList.size() +i][3] = dMaterialBuyList.get(i).getMBCount() == null ? "0.00" : dMaterialBuyList.get(i).getMBCount().toPlainString();
            content[dDeviceBuyList.size() +i][4] = dMaterialBuyList.get(i).getMBPriceall() == null ? "0.00" : dMaterialBuyList.get(i).getMBPriceall().toPlainString();
        }



        HSSFWorkbook wb = getHSSFWorkbook(aPBase, sheetName, title, content,dDeviceBuyList.size(), null);
        try {
            try {
                try {
                    fileName = new String(fileName.getBytes(), "ISO8859-1");
                } catch (UnsupportedEncodingException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
                response.setContentType("application/octet-stream;charset=ISO8859-1");
                response.setHeader("Content-Disposition", "attachment;filename=" + fileName);
                response.addHeader("Pargam", "no-cache");
                response.addHeader("Cache-Control", "no-cache");
            } catch (Exception ex) {
                ex.printStackTrace();
            }
            OutputStream os = response.getOutputStream();
            wb.write(os);
            os.flush();
            os.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    /**
     * 点位设备材料明细表【原】
     *
     * @param request
     * @param response
     * @throws IOException
     * @throws DocumentException
     */
//	@RequestMapping("/exportsbypoint")
//	public void exportsbypoint(HttpServletRequest request, HttpServletResponse response) throws IOException, DocumentException {
//		String guid = request.getParameter("guid");
//		APBaseEntity aPBase = aPBaseService.queryObject(guid);
//
//		response.setContentType("application/msword;charset=utf-8");
//		try {
//			response.setHeader("Content-Disposition", "attachment;filename=" + new String(((aPBase.getPBName()==null?"":aPBase.getPBName()) + "点位材料明细.doc").getBytes(), "iso-8859-1"));
//		} catch (UnsupportedEncodingException e) {
//			e.printStackTrace();
//		}
//
//		Document document = new Document();
//		BaseFont bfChinese = BaseFont.createFont("C:/WINDOWS/Fonts/SIMSUN.TTC,1", BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
//
//		RtfWriter2.getInstance(document, response.getOutputStream());
//		Font titleFontye = new Font(bfChinese,8,Font.BOLD);
//		HeaderFooter footer = new HeaderFooter(new Phrase("页码：",titleFontye), true);
//		footer.setAlignment(1);
//		footer.setBorder(Rectangle.NO_BORDER);
//		document.setFooter(footer);
//		document.open();
//		setexportspoint(document,bfChinese,aPBase);
//
//		document.close();
//
//
//	}


    /**
     * 点位设备材料明细表【新】
     *
     * @param request
     * @param response
     * @throws IOException
     * @throws DocumentException
     * @Time 2020-2-18 14:55:50
     */
    @RequestMapping("/exportsbypoint")
    public void exportsbypoint(HttpServletRequest request, HttpServletResponse response) throws IOException, DocumentException {
        String guid = request.getParameter("guid");
        APBaseEntity aPBase = aPBaseService.queryObject(guid);

        Map<String, Object> mapss = new HashMap<String, Object>();
        String wheres = " 1=1 ";
        wheres += " and  p_guid = '" + aPBase.getGuid() + "' ";
        mapss.put("filterSql", wheres + " ");
        List<APRangeEntity> aPRangeList = aPRangeService.queryList(mapss);

        String sheetName = "点位设备材料明细表";
        String fileName = aPBase.getPBName() + "点位设备材料明细表" + System.currentTimeMillis() + ".xls";
        HSSFWorkbook wb = getNewHSSFWorkbook(aPBase, sheetName, aPRangeList, null);
        try {
            fileName = new String(fileName.getBytes(), "ISO8859-1");

            response.setContentType("application/octet-stream;charset=ISO8859-1");
            response.setHeader("Content-Disposition", "attachment;filename=" + fileName);
            response.addHeader("Pargam", "no-cache");
            response.addHeader("Cache-Control", "no-cache");

            OutputStream os = response.getOutputStream();
            wb.write(os);
            os.flush();
            os.close();
        } catch (Exception ex) {
            ex.printStackTrace();
        }


    }


    /**
     * 设备材料购置表
     *
     * @param request
     * @param response
     * @throws IOException
     * @throws DocumentException
     */
    @RequestMapping("/exportsbymx")
    public void exportsbymx(HttpServletRequest request, HttpServletResponse response) throws IOException, DocumentException {
        String guid = request.getParameter("guid");
        APBaseEntity aPBase = aPBaseService.queryObject(guid);
        List<DMaterialBuyEntity> dMaterialBuyList = dMaterialBuyService.queryListout(aPBase.getGuid());
        List<DDeviceBuyEntity> dDeviceBuyList = dDeviceBuyService.queryListout(aPBase.getGuid());

        String[] title = {"名称", "规格及型号", "单位", "数量", "单价(元)", "合价(元)"};
        String fileName = aPBase.getPBName() + "设备材料购置表" + System.currentTimeMillis() + ".xls";
        String sheetName = "设备材料购置表";
        String[][] content = new String[dMaterialBuyList.size() + dDeviceBuyList.size()][title.length];
        for (int i = 0; i < dDeviceBuyList.size(); i++) {
            content[i][0] = dDeviceBuyList.get(i).getDBMidtype();
            content[i][1] = dDeviceBuyList.get(i).getDBName();
            content[i][2] = dDeviceBuyList.get(i).getDBUnit();
            content[i][3] = dDeviceBuyList.get(i).getDBCount() == null ? "0.00" : dDeviceBuyList.get(i).getDBCount().toString();
            content[i][4] = dDeviceBuyList.get(i).getDBPrice() == null ? "0.00" : dDeviceBuyList.get(i).getDBPrice().toPlainString();
            content[i][5] = dDeviceBuyList.get(i).getDBPriceall() == null ? "0.00" : dDeviceBuyList.get(i).getDBPriceall().toPlainString();
        }

        for (int i = 0; i < dMaterialBuyList.size(); i++) {
            content[dDeviceBuyList.size() + i][0] = dMaterialBuyList.get(i).getMBMidtype();
            content[dDeviceBuyList.size() + i][1] = dMaterialBuyList.get(i).getMBName();
            content[dDeviceBuyList.size() + i][2] = dMaterialBuyList.get(i).getMBUnit();
            content[dDeviceBuyList.size() + i][3] = dMaterialBuyList.get(i).getMBCount() == null ? "0.00" : dMaterialBuyList.get(i).getMBCount().toPlainString();
            content[dDeviceBuyList.size() + i][4] = dMaterialBuyList.get(i).getMBPrice() == null ? "0.00" : dMaterialBuyList.get(i).getMBPrice().toPlainString();
            content[dDeviceBuyList.size() + i][5] = dMaterialBuyList.get(i).getMBPriceall() == null ? "0.00" : dMaterialBuyList.get(i).getMBPriceall().toPlainString();
        }


        HSSFWorkbook wb = getHSSFWorkbook(aPBase, sheetName, title, content,dDeviceBuyList.size(), null);
        try {
            try {
                try {
                    fileName = new String(fileName.getBytes(), "ISO8859-1");
                } catch (UnsupportedEncodingException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
                response.setContentType("application/octet-stream;charset=ISO8859-1");
                response.setHeader("Content-Disposition", "attachment;filename=" + fileName);
                response.addHeader("Pargam", "no-cache");
                response.addHeader("Cache-Control", "no-cache");
            } catch (Exception ex) {
                ex.printStackTrace();
            }
            OutputStream os = response.getOutputStream();
            wb.write(os);
            os.flush();
            os.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }


    /**
     * 设备材料拆除表
     *
     * @param
     * @param
     * @throws IOException
     * @throws DocumentException
     */
    @RequestMapping("/exportRemove")
    public void exportRemove(HttpServletRequest request, HttpServletResponse response) throws IOException, DocumentException {

        try {
            String guid = request.getParameter("guid");
            APBaseEntity aPBase = aPBaseService.queryObject(guid);
            Map<String, Object> mapaPOther = new HashMap<>();

            //  拆除设备
            String dDeviceOldwheres = " 1=1 ";
            dDeviceOldwheres += " and  p_guid = '" + aPBase.getGuid() + "' ";
            dDeviceOldwheres += " and  d_r_datastate != '删除' ";
            mapaPOther.put("filterSql", dDeviceOldwheres + " ");
            List<DDeviceOldEntity> dDeviceOldList = dDeviceOldService.queryList(mapaPOther);
            List<DDeviceOldEntityOut> dDeviceOldOutList = new ArrayList<DDeviceOldEntityOut>();
            for (DDeviceOldEntity dDeviceOldEntity : dDeviceOldList) {
                DDeviceOldEntityOut dDeviceOldEntityOut = new DDeviceOldEntityOut();
                dDeviceOldEntityOut.setDRMidtype(dDeviceOldEntity.getDRMidtype());
                dDeviceOldEntityOut.setDRName(dDeviceOldEntity.getDRName());
                dDeviceOldEntityOut.setDRUnit("套");
                dDeviceOldEntityOut.setDRCount(new BigDecimal("1.000"));
                //  处置意见
                if (dDeviceOldEntity.getDROpinion() != null && dDeviceOldEntity.getDROpinion().equals("-9")) {
                    dDeviceOldEntityOut.setDROpinion("本项目利用");
                } else {
                    dDeviceOldEntityOut.setDROpinion(bDataDictionaryService.selectvaluebykey("opinion_type", dDeviceOldEntity.getDROpinion()));
                }
                dDeviceOldOutList.add(dDeviceOldEntityOut);
            }

            //  拆除材料
            mapaPOther.clear();
            String dMaterialOldwheres = " 1=1 ";
            dMaterialOldwheres += " and  p_guid = '" + aPBase.getGuid() + "' ";
            dMaterialOldwheres += " and  m_b_datastate != '删除' ";
            mapaPOther.put("filterSql", dMaterialOldwheres + " ");
            List<DMaterialOldEntity> dMaterialOldEntityList = dMaterialOldService.queryList(mapaPOther);
            List<DDeviceOldEntityOut> dMaterialOldOutList = new ArrayList<>();
            for (DMaterialOldEntity dMaterialOldEntity : dMaterialOldEntityList) {
                DDeviceOldEntityOut dDeviceOldEntityOut = new DDeviceOldEntityOut();
                dDeviceOldEntityOut.setDRMidtype(dMaterialOldEntity.getMBMidtype());
                dDeviceOldEntityOut.setDRName(dMaterialOldEntity.getMBName());
                dDeviceOldEntityOut.setDRUnit(dMaterialOldEntity.getMBUnit());
                dDeviceOldEntityOut.setDRCount(dMaterialOldEntity.getMBCount());
                dDeviceOldEntityOut.setDROpinion(bDataDictionaryService.selectvaluebykey("opinion_type", dMaterialOldEntity.getDROpinion()));
                dMaterialOldOutList.add(dDeviceOldEntityOut);
            }

            String[] title = {"名称", "规格及型号", "单位", "数量", "处置意见"};
            String fileName = aPBase.getPBName() + "设备材料拆除表" + System.currentTimeMillis() + ".xls";
            String sheetName = "设备材料拆除表";
            String[][] content = new String[dDeviceOldOutList.size() + dMaterialOldOutList.size()][title.length];

            for (int i = 0; i < dDeviceOldOutList.size(); i++) {

                content[i][0] = dDeviceOldOutList.get(i).getDRMidtype();
                content[i][1] = dDeviceOldOutList.get(i).getDRName();
                content[i][2] = dDeviceOldOutList.get(i).getDRUnit();
                content[i][3] = dDeviceOldOutList.get(i).getDRCount() == null ? "0.00" : dDeviceOldOutList.get(i).getDRCount().toString();
                content[i][4] = dDeviceOldOutList.get(i).getDROpinion();
            }

            for (int i = 0; i < dMaterialOldOutList.size(); i++) {

                content[dDeviceOldOutList.size() + i][0] = dMaterialOldOutList.get(i).getDRMidtype();
                content[dDeviceOldOutList.size() + i][1] = dMaterialOldOutList.get(i).getDRName();
                content[dDeviceOldOutList.size() + i][2] = dMaterialOldOutList.get(i).getDRUnit();
                content[dDeviceOldOutList.size() + i][3] = dMaterialOldOutList.get(i).getDRCount() == null ? "0.00" : dMaterialOldOutList.get(i).getDRCount().toPlainString();
                content[dDeviceOldOutList.size() + i][4] = dMaterialOldOutList.get(i).getDROpinion();
            }

            HSSFWorkbook wb = getHSSFWorkbook(aPBase, sheetName, title, content,dDeviceOldOutList.size(), null);

            try {
                try {
                    fileName = new String(fileName.getBytes(), "ISO8859-1");
                } catch (UnsupportedEncodingException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
                response.setContentType("application/octet-stream;charset=ISO8859-1");
                response.setHeader("Content-Disposition", "attachment;filename=" + fileName);
                response.addHeader("Pargam", "no-cache");
                response.addHeader("Cache-Control", "no-cache");
            } catch (Exception ex) {
                ex.printStackTrace();
            }
            OutputStream os = response.getOutputStream();
            wb.write(os);
            os.flush();
            os.close();
        } catch (Exception e) {
            e.printStackTrace();
        }

    }


    //	设备材料购置表、设备材料拆除表、材料汇总表
    public static HSSFWorkbook getHSSFWorkbook(APBaseEntity aPBase, String sheetName, String[] title, String[][] values,int listSize , HSSFWorkbook wb) {

        // 第一步，创建一个HSSFWorkbook，对应一个Excel文件
        if (wb == null) {
            wb = new HSSFWorkbook();
        }

        // 第二步，在workbook中添加一个sheet,对应Excel文件中的sheet
        HSSFSheet sheet = wb.createSheet(sheetName);

        // 第三步，在sheet中添加表头第0行,注意老版本poi对Excel的行数列数有限制
        HSSFRow row = sheet.createRow(0);

        // 第四步，创建单元格，并设置值表头 设置表头居中
        HSSFCellStyle style = wb.createCellStyle();

        // 表头样式
        style.setAlignment(HorizontalAlignment.CENTER); // 居中

        style.setBorderBottom(BorderStyle.THIN); //下边框
        style.setBorderLeft(BorderStyle.THIN);//左边框
        style.setBorderTop(BorderStyle.THIN);//上边框
        style.setBorderRight(BorderStyle.THIN);//右边框

        HSSFFont font = wb.createFont();
        font.setFontName("宋体");
        font.setBold(true);
        font.setFontHeightInPoints((short) 10);//设置字体大小
        style.setFont(font);//选择需要用到的字体格式


        // 设置表格列宽
        sheet.setColumnWidth(0, 4000);
        sheet.setColumnWidth(1, 10000);
        sheet.setColumnWidth(2, 4000);
        sheet.setColumnWidth(3, 4000);
        sheet.setColumnWidth(4, 4000);

        // 内容单元格样式
        CellStyle style1 = wb.createCellStyle();
        style1.setAlignment(HorizontalAlignment.CENTER); // 居中
        style1.setBorderBottom(BorderStyle.THIN); //下边框
        style1.setBorderLeft(BorderStyle.THIN);//左边框
        style1.setBorderTop(BorderStyle.THIN);//上边框
        style1.setBorderRight(BorderStyle.THIN);//右边框

        //声明列对象
        HSSFCell cell = null;

//        // 表头(合并单元格)
//        cell = row.createCell(0);
//        cell.setCellValue(aPBase.getPBName() + "_" + sheetName);
//        cell.setCellStyle(style);
//        CellRangeAddress region1 = new CellRangeAddress(0, 0, 0, 4);
//        sheet.addMergedRegion(region1);
//
//        //创建标题
//        row = sheet.createRow(1);
//        for (int i = 0; i < title.length; i++) {
//            cell = row.createCell(i);
//            cell.setCellValue(title[i]);
//            cell.setCellStyle(style);
//        }
//
//
//        //创建内容
//        for (int i = 0; i < values.length; i++) {
//            row = sheet.createRow(i + 2);
//            for (int j = 0; j < values[i].length; j++) {
//                //将内容按顺序赋给对应的列对象
////				row.createCell(j).setCellValue(values[i][j]);
//                cell = row.createCell(j);
//                cell.setCellValue(values[i][j]);
//                cell.setCellStyle(style1);
//            }
//        }


        // 表头(合并单元格)
        cell = row.createCell(0);
        cell.setCellValue(aPBase.getPBName() + "_" + sheetName);
        cell.setCellStyle(style);
        CellRangeAddress region1 = null;
        if (sheetName.equals("材料汇总表") || sheetName.equals("设备材料拆除表")) {
            region1 = new CellRangeAddress(0, 0, 0, 4);
        } else {
            region1 = new CellRangeAddress(0, 0, 0, 5);
        }
        sheet.addMergedRegion(region1);

        //  主要设备行
        row = sheet.createRow(1);
        cell = row.createCell(0);
        cell.setCellValue("主要设备");
        cell.setCellStyle(style);
        CellRangeAddress region2 = null;
        if (sheetName.equals("材料汇总表") || sheetName.equals("设备材料拆除表")) {
            region2 = new CellRangeAddress(1, 1, 0, 4);
        } else {
            region2 = new CellRangeAddress(1, 1, 0, 5);
        }
        sheet.addMergedRegion(region2);
        setBorderForMergeCell(1, region2, sheet);

        //创建标题
        row = sheet.createRow(2);
        for (int i = 0; i < title.length; i++) {
            cell = row.createCell(i);
            cell.setCellValue(title[i]);
            cell.setCellStyle(style);
        }

        boolean isTrue = true;  //  材料表头的循环
        boolean isFor = false;  //  材料内容的循环
        //创建内容
        for (int i = 0; i < values.length; i++) {

            if (i < listSize) {   //  先创建设备信息
                row = sheet.createRow(i + 3);
                for (int j = 0; j < values[i].length; j++) {
                    cell = row.createCell(j);
                    cell.setCellValue(values[i][j]);
                    cell.setCellStyle(style1);
                }

            } else {  //  再创建材料信息

                if (isTrue) { //  创建表头栏
                    row = sheet.createRow(i + 3);
                    cell = row.createCell(0);
                    cell.setCellValue("主要材料");
                    cell.setCellStyle(style);
                    CellRangeAddress region3 = null;
                    if (sheetName.equals("材料汇总表") || sheetName.equals("设备材料拆除表")) {
                        region3 = new CellRangeAddress(i + 3, i + 3, 0, 4);
                    } else {
                        region3 = new CellRangeAddress(i + 3, i + 3, 0, 5);
                    }
                    sheet.addMergedRegion(region3);
                    setBorderForMergeCell(1, region3, sheet);

                    row = sheet.createRow(i + 4);
                    for (int m = 0; m < title.length; m++) {    //  表头栏
                        cell = row.createCell(m);
                        cell.setCellValue(title[m]);
                        cell.setCellStyle(style);
                    }

                    isTrue = false;
                    isFor = true;
                }
                if (isFor) {
                    row = sheet.createRow(i + 5);
                    for (int j = 0; j < values[i].length; j++) {
                        cell = row.createCell(j);
                        cell.setCellValue(values[i][j]);
                        cell.setCellStyle(style1);
                    }
                }
            }

        }


        return wb;
    }



    //  点位设备材料明细表
    public HSSFWorkbook getNewHSSFWorkbook(APBaseEntity aPBase, String sheetName, List<APRangeEntity> aPRangeList, HSSFWorkbook wb) {

        // 第一步，创建一个HSSFWorkbook，对应一个Excel文件
        if (wb == null) {
            wb = new HSSFWorkbook();
        }



        for (APRangeEntity aPRangeEntity : aPRangeList) {



            // 第二步，在workbook中添加一个sheet,对应Excel文件中的sheet
            HSSFSheet sheet = wb.createSheet(aPRangeEntity.getPRName()+sheetName);

            // 第三步，在sheet中添加表头第0行,注意老版本poi对Excel的行数列数有限制
            HSSFRow row = sheet.createRow(0);

            // 第四步，创建单元格，并设置值表头 设置表头居中
            HSSFCellStyle style = wb.createCellStyle();

            // 表头样式
            style.setAlignment(HorizontalAlignment.CENTER);         // 水平居中
            style.setVerticalAlignment(VerticalAlignment.CENTER);   // 垂直居中
            style.setBorderBottom(BorderStyle.THIN); //下边框
            style.setBorderLeft(BorderStyle.THIN);//左边框
            style.setBorderTop(BorderStyle.THIN);//上边框
            style.setBorderRight(BorderStyle.THIN);//右边框

            //  表头字体
            HSSFFont font = wb.createFont();
            font.setFontName("宋体");
            font.setBold(true);
            font.setFontHeightInPoints((short) 10);//设置字体大小
            style.setFont(font);//选择需要用到的字体格式

            //  正文字体
            HSSFFont font1 = wb.createFont();
            font1.setFontName("宋体");
            font1.setBold(false);
            font1.setFontHeightInPoints((short) 10);//设置字体大小

            // 设置表格列宽
            sheet.setColumnWidth(0, 4000);
            sheet.setColumnWidth(1, 4000);
            sheet.setColumnWidth(2, 6000);
            sheet.setColumnWidth(3, 10000);
            sheet.setColumnWidth(4, 20000);
            sheet.setColumnWidth(5, 2000);
            sheet.setColumnWidth(6, 3000);

            // 内容单元格样式
            CellStyle style1 = wb.createCellStyle();
            style1.setAlignment(HorizontalAlignment.CENTER);            // 水平居中
            style1.setVerticalAlignment(VerticalAlignment.CENTER);      // 垂直居中
            style1.setBorderBottom(BorderStyle.THIN);                   //下边框
            style1.setBorderLeft(BorderStyle.THIN);                     //左边框
            style1.setBorderTop(BorderStyle.THIN);                      //上边框
            style1.setBorderRight(BorderStyle.THIN);                    //右边框
            style1.setFont(font1);

            //声明列对象
            HSSFCell cell = null;

            //  标题栏
            cell = row.createCell(0);
            cell.setCellValue(aPBase.getPBName() + "点位设备材料明细");
            cell.setCellStyle(style);
            CellRangeAddress region1 = new CellRangeAddress(0, 0, 0, 6);
            sheet.addMergedRegion(region1);
//        setBorderForMergeCell(1,region1,sheet);


            String[] title = {"杆塔点位", "新增类型", "类别", "名称", "规格型号", "单位", "数量"};



            //  项目范围栏
            row = sheet.createRow(1);
            cell = row.createCell(0);
            cell.setCellValue(aPRangeEntity.getPRName() + "点位设备材料明细");
            cell.setCellStyle(style);
            CellRangeAddress region2 = new CellRangeAddress(1, 1, 0, 6);
            sheet.addMergedRegion(region2);
            setBorderForMergeCell(1, region2, sheet);

            //  表头栏
            row = sheet.createRow(2);
            for (int i = 0; i < title.length; i++) {
                cell = row.createCell(i);
                cell.setCellValue(title[i]);
                cell.setCellStyle(style);
            }

            Map<String, Object> mapapole = new HashMap<>();
            String polewheres = " 1=1 ";
            polewheres += " and  p_guid = '" + aPBase.getGuid() + "' ";
            polewheres += " and  p_r_guid = '" + aPRangeEntity.getGuid() + "' ";
            polewheres += " and  p_p_datastate!= '删除' ";
            mapapole.put("filterSql", polewheres + " order by p_r_guid,   CONVERT(Right(p_p_code,LENGTH(p_p_code)-instr(p_p_code, '#')) ,SIGNED) asc ");

            int k = 0;  //  起始行
            int j = 2;  //  结束行
            int m = 0;  //  没有点位工作内容的行数
            boolean isTrue = true;
            List<DPointEntity> dPointList = dPointService.queryList(mapapole);
            for (DPointEntity dPointEntity : dPointList) {
                List<ReOutMeterAndDev> ReOutMeterAndDevlist = dWorkContentService.getMeterAndDevByPoint(dPointEntity.getGuid());

                if (ReOutMeterAndDevlist.size() > 0) { //  点位有工作内容时

                    for (int i = 0; i < ReOutMeterAndDevlist.size(); i++) {
                        if (i == 0) {
                            k = j + 1;
                        }
                        row = sheet.createRow(j + 1 + m);
                        cell = row.createCell(0);
                        cell.setCellValue(dPointEntity.getPPCode() + dPointEntity.getPPName());
                        cell.setCellStyle(style1);

                        cell = row.createCell(1);
                        cell.setCellValue(ReOutMeterAndDevlist.get(i).getWorktype());
                        cell.setCellStyle(style1);

                        cell = row.createCell(2);
                        cell.setCellValue(ReOutMeterAndDevlist.get(i).getMidtype());
                        cell.setCellStyle(style1);

                        cell = row.createCell(3);
                        cell.setCellValue(ReOutMeterAndDevlist.get(i).getMname());
                        cell.setCellStyle(style1);

                        cell = row.createCell(4);
                        cell.setCellValue(ReOutMeterAndDevlist.get(i).getParameter());
                        cell.setCellStyle(style1);

                        cell = row.createCell(5);
                        cell.setCellValue(ReOutMeterAndDevlist.get(i).getUnit());
                        cell.setCellStyle(style1);

                        cell = row.createCell(6);
                        cell.setCellValue(ReOutMeterAndDevlist.get(i).getCounts());
                        cell.setCellStyle(style1);


                        j++;


                    }

                    //  合并 杆塔点位列
                    if(k+m != j+m) {
                        CellRangeAddress region3 = new CellRangeAddress(k + m, j + m, 0, 0);
                        sheet.addMergedRegion(region3);
                        setBorderForMergeCell(1, region3, sheet);
                    }

                } else {  //  点位无工作内容时
                    row = sheet.createRow(j + 1 + m);
                    cell = row.createCell(0);
                    cell.setCellValue(dPointEntity.getPPCode() + dPointEntity.getPPName());
                    cell.setCellStyle(style1);

                    cell = row.createCell(1);
                    cell.setCellValue("");
                    cell.setCellStyle(style);

                    cell = row.createCell(2);
                    cell.setCellValue("");
                    cell.setCellStyle(style);

                    cell = row.createCell(3);
                    cell.setCellValue("");
                    cell.setCellStyle(style);

                    cell = row.createCell(4);
                    cell.setCellValue("");
                    cell.setCellStyle(style);

                    cell = row.createCell(5);
                    cell.setCellValue("");
                    cell.setCellStyle(style);

                    cell = row.createCell(6);
                    cell.setCellValue("");
                    cell.setCellStyle(style);

                    m++;
                }
            }
        }

        return wb;
    }

    /**
     * 合并单元格设置边框
     *
     * @param i
     * @param cellRangeTitle
     * @param sheet
     * @param
     */
    private static void setBorderForMergeCell(int i, CellRangeAddress cellRangeTitle, HSSFSheet sheet) {
        RegionUtil.setBorderBottom(i, cellRangeTitle, sheet);
        RegionUtil.setBorderLeft(i, cellRangeTitle, sheet);
        RegionUtil.setBorderRight(i, cellRangeTitle, sheet);
        RegionUtil.setBorderTop(i, cellRangeTitle, sheet);
    }

    //	点位设备材料明细表
    public void setexportspoint(Document document, BaseFont bfChinese, APBaseEntity aPBase) throws DocumentException {

        //表题字体
        Font titleFont = new Font(bfChinese, 11, Font.BOLD);
        //表格字体
        Font contextFont = new Font(bfChinese, 8, Font.NORMAL);
        // 签字字体
        Font qinFont = new Font(bfChinese, 10, Font.NORMAL);
        Paragraph title = new Paragraph(aPBase.getPBName() + "点位材料明细");
        title.setAlignment(Element.ALIGN_CENTER);
        title.setFont(titleFont);
        document.add(title);
        document.add(new Paragraph(""));
        Map<String, Object> mapss = new HashMap<String, Object>();
        String wheres = " 1=1 ";
        wheres += " and  p_guid = '" + aPBase.getGuid() + "' ";
        mapss.put("filterSql", wheres + " ");
        List<APRangeEntity> aPRangeList = aPRangeService.queryList(mapss);
        for (APRangeEntity aPRangeEntity : aPRangeList) {
            Paragraph mytitle = new Paragraph(aPRangeEntity.getPRName() + "点位材料明细");
            mytitle.setAlignment(Element.ALIGN_CENTER);
            mytitle.setFont(contextFont);
            document.add(mytitle);

            Map<String, Object> mapapole = new HashMap<>();
            String polewheres = " 1=1 ";
            polewheres += " and  p_guid = '" + aPBase.getGuid() + "' ";
            polewheres += " and  p_r_guid = '" + aPRangeEntity.getGuid() + "' ";
            polewheres += " and  p_p_datastate!= '删除' ";
            mapapole.put("filterSql", polewheres + " ");
            List<DPointEntity> dPointList = dPointService.queryList(mapapole);
            Table table = new Table(7);
            int[] withs = {1, 2, 2, 3, 3, 1, 1};
            table.setWidths(withs);
            /** 表格所占页面宽度 author:yyli Sep 15, 2010 */
            table.setWidth(90);
            /** 居中显示 author:yyli Sep 15, 2010 */
            table.setAlignment(Element.ALIGN_CENTER);
            /** 自动填满 author:yyli Sep 15, 2010 */
            table.setAutoFillEmptyCells(true);
            OutPutUtils.addcell(table, "杆塔点位", 0, 0, true, contextFont);
            OutPutUtils.addcell(table, "新增类型", 0, 0, true, contextFont);
            OutPutUtils.addcell(table, "类别", 0, 0, true, contextFont);
            OutPutUtils.addcell(table, "名称", 0, 0, true, contextFont);
            OutPutUtils.addcell(table, "规格型号", 0, 0, true, contextFont);
            OutPutUtils.addcell(table, "单位", 0, 0, true, contextFont);
            OutPutUtils.addcell(table, "数量", 0, 0, true, contextFont);
            for (DPointEntity dPointEntity : dPointList) {
                List<ReOutMeterAndDev> ReOutMeterAndDevlist = dWorkContentService.getMeterAndDevByPoint(dPointEntity.getGuid());
                OutPutUtils.addcell(table, dPointEntity.getPPCode() + dPointEntity.getPPName(), ReOutMeterAndDevlist.size(), 0, true, contextFont);
                if (ReOutMeterAndDevlist.size() > 0) {
                    for (ReOutMeterAndDev reOutMeterAndDev : ReOutMeterAndDevlist) {
                        OutPutUtils.addcell(table, reOutMeterAndDev.getWorktype(), 0, 0, true, contextFont);
                        OutPutUtils.addcell(table, reOutMeterAndDev.getMidtype(), 0, 0, true, contextFont);
                        OutPutUtils.addcell(table, reOutMeterAndDev.getMname(), 0, 0, true, contextFont);
                        OutPutUtils.addcell(table, reOutMeterAndDev.getParameter(), 0, 0, true, contextFont);
                        OutPutUtils.addcell(table, reOutMeterAndDev.getUnit(), 0, 0, true, contextFont);
                        OutPutUtils.addcell(table, reOutMeterAndDev.getCounts() + "", 0, 0, true, contextFont);

                    }
                } else {
                    OutPutUtils.addcell(table, "", 0, 0, true, contextFont);
                    OutPutUtils.addcell(table, "", 0, 0, true, contextFont);
                    OutPutUtils.addcell(table, "", 0, 0, true, contextFont);
                    OutPutUtils.addcell(table, "", 0, 0, true, contextFont);
                    OutPutUtils.addcell(table, "", 0, 0, true, contextFont);
                    OutPutUtils.addcell(table, "", 0, 0, true, contextFont);

                }

            }
            document.add(table);
            document.add(new Paragraph(""));
        }

    }


    //	申请书
    public void setexports(Document document, BaseFont bfChinese, APBaseEntity aPBase) throws DocumentException {
        Map<String, Object> mapaPOther = new HashMap<>();

        String mapaPOtherwheres = " 1=1 ";
        mapaPOtherwheres += " and  p_guid = '" + aPBase.getGuid() + "' ";
        mapaPOtherwheres += " and  p_o_datastate != '删除' ";
        mapaPOther.put("filterSql", mapaPOtherwheres + " ");
        List<APOtherEntity> aPOtherList = aPOtherService.queryList(mapaPOther);
        APOtherEntity aPOther = aPOtherList.get(0);
        SysDeptEntity sysDeptEntity = sysDeptService.queryObject(aPBase.getPBOrgid());
        mapaPOther.clear();
        String aPCriteriawheres = " 1=1 ";
        aPCriteriawheres += " and  p_guid = '" + aPBase.getGuid() + "' ";
        aPCriteriawheres += " and  p_c_datastate != '删除' ";
        mapaPOther.put("filterSql", aPCriteriawheres + " ");
        List<APCriteriaEntity> aPCriteriaList = aPCriteriaService.queryList(mapaPOther);
        String aPCriteria1 = "";
        String aPCriteria2 = "";
        String aPCriteria3 = "";
        for (APCriteriaEntity aPCriteriaEntity : aPCriteriaList) {
            if (!aPCriteria1.contains(aPCriteriaEntity.getPCName())) {
                aPCriteria1 += aPCriteriaEntity.getPCName() + "；";
            }
            if (!aPCriteria2.contains(aPCriteriaEntity.getPCChapter())) {
                aPCriteria2 += aPCriteriaEntity.getPCChapter() + "；";
            }
            if (!aPCriteria3.contains(aPCriteriaEntity.getPCCriteria())) {
                aPCriteria3 += aPCriteriaEntity.getPCCriteria() + "";
            }
        }
        mapaPOther.clear();
        String aPEstimatewheres = " 1=1 ";
        aPEstimatewheres += " and  p_guid = '" + aPBase.getGuid() + "' ";
        aPEstimatewheres += " and  p_e_datastate != '删除' ";
        mapaPOther.put("filterSql", aPEstimatewheres + " ");
        List<APEstimateEntity> APEstimateEntitylist = aPEstimateService.queryList(mapaPOther);
        //总费用
        BigDecimal tole = BigDecimal.ZERO;
        //建筑工程费
        BigDecimal tole1 = BigDecimal.ZERO;
        //安装费
        BigDecimal tole2 = BigDecimal.ZERO;
        //购置费
        BigDecimal tole3 = BigDecimal.ZERO;
        //其他费用
        BigDecimal tole4 = BigDecimal.ZERO;
        for (APEstimateEntity aPEstimateEntity : APEstimateEntitylist) {
            BigDecimal tol = aPEstimateEntity.getPEFinal() == null ? BigDecimal.ZERO : aPEstimateEntity.getPEFinal();
            tole = tole.add(tol);

            if (PriceConfig.otherPrice.contains(aPEstimateEntity.getPEItem())) {
                tole4 = tole4.add(tol);
            } else if (PriceConfig.buildPrice.contains(aPEstimateEntity.getPEItem())) {
                tole1 = tole1.add(tol);
            } else if (PriceConfig.buyPrice.contains(aPEstimateEntity.getPEItem())) {
                tole3 = tole3.add(tol);
            } else {
                tole2 = tole2.add(tol);
            }
        }

        mapaPOther.clear();
        String aPCostwheres = " 1=1 ";
        aPCostwheres += " and  p_guid = '" + aPBase.getGuid() + "' ";
        aPCostwheres += " and  p_c_datastate != '删除' ";
        mapaPOther.put("filterSql", aPCostwheres + " ");
        List<APCostEntity> aPCostList = aPCostService.queryList(mapaPOther);

        mapaPOther.clear();
        String dDeviceOldwheres = " 1=1 ";
        dDeviceOldwheres += " and  p_guid = '" + aPBase.getGuid() + "' ";
        dDeviceOldwheres += " and  d_r_datastate != '删除' ";
        mapaPOther.put("filterSql", dDeviceOldwheres + " ");
        List<DDeviceOldEntity> dDeviceOldList = dDeviceOldService.queryList(mapaPOther);


        List<DDeviceBuyEntity> dDeviceBuyList = dDeviceBuyService.queryListout(aPBase.getGuid());


        List<DMaterialBuyEntity> dMaterialBuyList = dMaterialBuyService.queryListout(aPBase.getGuid());


        //表题字体
        Font titleFont = new Font(bfChinese, 11, Font.BOLD);
        //表格字体
        Font contextFont = new Font(bfChinese, 8, Font.NORMAL);
        // 签字字体
        Font qinFont = new Font(bfChinese, 10, Font.NORMAL);
        Paragraph title = new Paragraph("配网技改/修理项目申请书（适用于总投资100万元以下的配网技改/修理项目）");
        title.setAlignment(Element.ALIGN_CENTER);
        title.setFont(titleFont);
        document.add(title);

        Table table = new Table(13);
        int[] withs = {1, 3, 3, 2, 2, 3, 3, 2, 2, 2, 2, 2, 4};
        table.setWidths(withs);
        /** 表格所占页面宽度 author:yyli Sep 15, 2010 */
        table.setWidth(90);
        /** 居中显示 author:yyli Sep 15, 2010 */
        table.setAlignment(Element.ALIGN_CENTER);
        /** 自动填满 author:yyli Sep 15, 2010 */
        table.setAutoFillEmptyCells(true);

        OutPutUtils.addcell(table, "项目名称", 0, 3, true, contextFont);
        OutPutUtils.addcell(table, aPBase.getPBName(), 0, 10, false, contextFont);
        OutPutUtils.addcell(table, "项目单位", 0, 3, true, contextFont);
        OutPutUtils.addcell(table, sysDeptEntity.getName(), 0, 7, false, contextFont);
        OutPutUtils.addcell(table, "项目实施年度", 0, 2, true, contextFont);
        OutPutUtils.addcell(table, aPOther.getPOYear(), 0, 0, true, contextFont);
        OutPutUtils.addcell(table, "项目内容", 0, 3, true, contextFont);
        OutPutUtils.addcell(table, aPOther.getPOContent(), 0, 10, false, contextFont);
        OutPutUtils.addcell(table, "是否反措项目", 0, 3, true, contextFont);
        OutPutUtils.addcell(table, aPOther.getPOIsstep(), 0, 7, false, contextFont);
        OutPutUtils.addcell(table, "是否规划项目", 0, 2, true, contextFont);
        OutPutUtils.addcell(table, aPOther.getPOIsplan(), 0, 0, true, contextFont);
        OutPutUtils.addcell(table, "重点投入方向", 0, 3, true, contextFont);
        OutPutUtils.addcell(table, aPOther.getPODirection(), 0, 10, false, contextFont);
        //动态跨行
        OutPutUtils.addcell(table, "必要性", 5 + dDeviceOldList.size() + 1 + 7 + 7 + 7 + 1, 0, true, contextFont);
        OutPutUtils.addcell(table, "预算标准", 0, 2, true, contextFont);
        OutPutUtils.addcell(table, "依据《南方电网生产项目准入及预算标准》:" + aPCriteria1, 0, 10, false, contextFont);
        OutPutUtils.addcell(table, "准入条件", 2, 0, true, contextFont);
        OutPutUtils.addcell(table, "对应条款", 0, 0, true, contextFont);
        OutPutUtils.addcell(table, "依据《南方电网生产项目准入及预算标准》:" + aPCriteria2, 0, 10, false, contextFont);
        OutPutUtils.addcell(table, "条款详述", 0, 0, true, contextFont);
        OutPutUtils.addcell(table, "依据《南方电网生产项目准入及预算标准》:" + aPCriteria3, 0, 10, false, contextFont);
        OutPutUtils.addcell(table, "设备（设施）基本情况", 0, 2, true, contextFont);
        OutPutUtils.addcell(table, aPOther.getPODevice(), 0, 10, false, contextFont);
        OutPutUtils.addcell(table, "存在问题", 0, 2, true, contextFont);
        OutPutUtils.addcell(table, aPOther.getPOProblem(), 0, 10, false, contextFont);
        OutPutUtils.addcell(table, "一、改造/检修/拆除设备清单（项目主要改造/检修/拆除的资产级设备明细）", 0, 12, false, contextFont);
        OutPutUtils.addcell(table, "设备名称", 0, 0, true, contextFont);
        OutPutUtils.addcell(table, "设备编号", 0, 0, true, contextFont);
        OutPutUtils.addcell(table, "设备厂家", 0, 0, true, contextFont);
        OutPutUtils.addcell(table, "设备型号", 0, 0, true, contextFont);
        OutPutUtils.addcell(table, "出厂日期", 0, 0, true, contextFont);
        OutPutUtils.addcell(table, "投运日期", 0, 0, true, contextFont);
        OutPutUtils.addcell(table, "固定资产卡片编号", 0, 0, true, contextFont);
        OutPutUtils.addcell(table, "资产原值（万元）", 0, 0, true, contextFont);
        OutPutUtils.addcell(table, "资产净值（万元）", 0, 0, true, contextFont);
        OutPutUtils.addcell(table, "资产净值率", 0, 0, true, contextFont);
        OutPutUtils.addcell(table, "拟拆除日期", 0, 0, true, contextFont);
        OutPutUtils.addcell(table, "处置意见", 0, 0, true, contextFont);


        for (DDeviceOldEntity dDeviceOldEntity : dDeviceOldList) {
            OutPutUtils.addcell(table, dDeviceOldEntity.getDRName(), 0, 0, true, contextFont);
            OutPutUtils.addcell(table, "", 0, 0, true, contextFont);
            OutPutUtils.addcell(table, dDeviceOldEntity.getDRFactory(), 0, 0, true, contextFont);
            OutPutUtils.addcell(table, dDeviceOldEntity.getDRParameter(), 0, 0, true, contextFont);
            OutPutUtils.addcell(table, dDeviceOldEntity.getDRFactorydate() == null ? "" : DateUtils.format(dDeviceOldEntity.getDRFactorydate(), "yyyy-MM-dd"), 0, 0, true, contextFont);
            OutPutUtils.addcell(table, dDeviceOldEntity.getDRDeliverydate() == null ? "" : DateUtils.format(dDeviceOldEntity.getDRDeliverydate(), "yyyy-MM-dd"), 0, 0, true, contextFont);
            OutPutUtils.addcell(table, dDeviceOldEntity.getDRCode(), 0, 0, true, contextFont);
            OutPutUtils.addcell(table, dDeviceOldEntity.getDRPrice() == null ? "" : dDeviceOldEntity.getDRPrice().toPlainString(), 0, 0, true, contextFont);
            OutPutUtils.addcell(table, dDeviceOldEntity.getDRNetassets() == null ? "" : dDeviceOldEntity.getDRNetassets().toPlainString(), 0, 0, true, contextFont);
            OutPutUtils.addcell(table, dDeviceOldEntity.getDRRate() == null ? "" : dDeviceOldEntity.getDRRate().toPlainString(), 0, 0, true, contextFont);
            OutPutUtils.addcell(table, dDeviceOldEntity.getDRRemovedate() == null ? "" : DateUtils.format(dDeviceOldEntity.getDRRemovedate(), "yyyy-MM-dd"), 0, 0, true, contextFont);
            if (dDeviceOldEntity.getDROpinion() != null && dDeviceOldEntity.getDROpinion().equals("-9")) {
                OutPutUtils.addcell(table, "本项目利用", 0, 0, true, contextFont);
            } else {
                OutPutUtils.addcell(table, bDataDictionaryService.selectvaluebykey("opinion_type", dDeviceOldEntity.getDROpinion()), 0, 0, true, contextFont);
            }
        }

        OutPutUtils.addcell(table, "二、缺陷（故障）记录", 0, 12, false, contextFont);
        OutPutUtils.addcell(table, "序号", 0, 0, true, contextFont);
        OutPutUtils.addcell(table, "缺陷编号", 0, 0, true, contextFont);
        OutPutUtils.addcell(table, "缺陷类别", 0, 0, true, contextFont);
        OutPutUtils.addcell(table, "严重等级", 0, 0, true, contextFont);
        OutPutUtils.addcell(table, "缺陷表象", 0, 0, true, contextFont);
        OutPutUtils.addcell(table, "发现人描述", 0, 4, true, contextFont);
        OutPutUtils.addcell(table, "发现人意见", 0, 2, true, contextFont);
        OutPutUtils.addcell(table, "发现时间", 0, 0, true, contextFont);

        for (int i = 0; i < 5; i++) {
            OutPutUtils.addcell(table, "", 0, 0, true, contextFont);
            OutPutUtils.addcell(table, "", 0, 0, true, contextFont);
            OutPutUtils.addcell(table, "", 0, 0, true, contextFont);
            OutPutUtils.addcell(table, "", 0, 0, true, contextFont);
            OutPutUtils.addcell(table, "", 0, 0, true, contextFont);
            OutPutUtils.addcell(table, "", 0, 4, true, contextFont);
            OutPutUtils.addcell(table, "", 0, 2, true, contextFont);
            OutPutUtils.addcell(table, "", 0, 0, true, contextFont);
        }

        OutPutUtils.addcell(table, "三、设备状态评价与风险评估（改造设备状态评价与风险评估结果）", 0, 12, false, contextFont);
        OutPutUtils.addcell(table, "年份", 0, 0, true, contextFont);
        OutPutUtils.addcell(table, "设备", 0, 2, true, contextFont);
        OutPutUtils.addcell(table, "状态", 0, 0, true, contextFont);
        OutPutUtils.addcell(table, "风险等级", 0, 0, true, contextFont);
        OutPutUtils.addcell(table, "扣分点", 0, 2, true, contextFont);
        OutPutUtils.addcell(table, "扣分值", 0, 2, true, contextFont);
        OutPutUtils.addcell(table, "重要度评价", 0, 2, true, contextFont);
        OutPutUtils.addcell(table, "运维等级", 0, 0, true, contextFont);

        for (int i = 0; i < 5; i++) {
            OutPutUtils.addcell(table, "", 0, 0, true, contextFont);
            OutPutUtils.addcell(table, "", 0, 2, true, contextFont);
            OutPutUtils.addcell(table, "", 0, 0, true, contextFont);
            OutPutUtils.addcell(table, "", 0, 0, true, contextFont);
            OutPutUtils.addcell(table, "", 0, 2, true, contextFont);
            OutPutUtils.addcell(table, "", 0, 2, true, contextFont);
            OutPutUtils.addcell(table, "", 0, 2, true, contextFont);
            OutPutUtils.addcell(table, "", 0, 0, true, contextFont);
        }
        OutPutUtils.addcell(table, "四、关联生产项目历史（历史开展过的技改、大修项目，日常维修项目需列出近三年费用情况））", 0, 12, false, contextFont);
        OutPutUtils.addcell(table, "立项年份", 0, 0, true, contextFont);
        OutPutUtils.addcell(table, "项目类型", 0, 0, true, contextFont);
        OutPutUtils.addcell(table, "项目编码", 0, 2, true, contextFont);
        OutPutUtils.addcell(table, "项目名称", 0, 3, true, contextFont);
        OutPutUtils.addcell(table, "项目总投资（万元）", 0, 2, true, contextFont);
        OutPutUtils.addcell(table, "项目简要内容", 0, 3, true, contextFont);


        for (int i = 0; i < 5; i++) {
            OutPutUtils.addcell(table, "", 0, 0, true, contextFont);
            OutPutUtils.addcell(table, "", 0, 0, true, contextFont);
            OutPutUtils.addcell(table, "", 0, 2, true, contextFont);
            OutPutUtils.addcell(table, "", 0, 3, true, contextFont);
            OutPutUtils.addcell(table, "", 0, 2, true, contextFont);
            OutPutUtils.addcell(table, "", 0, 3, true, contextFont);
        }
        OutPutUtils.addcell(table, "项目方案", 4, 0, true, contextFont);

        OutPutUtils.addcell(table, "实施必要性", 0, 2, true, contextFont);
        OutPutUtils.addcell(table, aPOther.getPOMust(), 0, 10, false, contextFont);

        //动态跨行
        OutPutUtils.addcell(table, "技术实施方案", 0, 2, true, contextFont);
        OutPutUtils.addcell(table, aPOther.getPOSkill(), 0, 10, false, contextFont);
        OutPutUtils.addcell(table, "停电施工方案\n（临时过渡方案）", 0, 2, true, contextFont);
        OutPutUtils.addcell(table, aPOther.getPOPower(), 0, 10, false, contextFont);
        OutPutUtils.addcell(table, "对环境的影响及经济或社会效益预测", 0, 2, true, contextFont);
        OutPutUtils.addcell(table, aPOther.getPOEffect(), 0, 10, false, contextFont);

        //动态跨行
        OutPutUtils.addcell(table, "项目造价", 4 + 2 + aPCostList.size() + dDeviceBuyList.size() + 2 + dMaterialBuyList.size() + 2, 0, true, contextFont);
        OutPutUtils.addcell(table, "年度计划资金分解（万元）", 2, 3, true, contextFont);
        OutPutUtils.addcell(table, "项目总投资", 0, 2, true, contextFont);
        OutPutUtils.addcell(table, tole.toPlainString(), 0, 7, true, contextFont);
        OutPutUtils.addcell(table, "____年计划投资", 0, 2, true, contextFont);
        OutPutUtils.addcell(table, "", 0, 1, true, contextFont);
        OutPutUtils.addcell(table, "____年计划投资", 0, 2, true, contextFont);
        OutPutUtils.addcell(table, "", 0, 1, true, contextFont);
        OutPutUtils.addcell(table, "____年计划投资", 0, 2, true, contextFont);
        OutPutUtils.addcell(table, "", 0, 1, true, contextFont);

        OutPutUtils.addcell(table, "费用组成（万元）", 2, 3, true, contextFont);
        OutPutUtils.addcell(table, "建筑工程费", 0, 3, true, contextFont);
        OutPutUtils.addcell(table, "安装工程费（包含调试费）", 0, 3, true, contextFont);
        OutPutUtils.addcell(table, "设备购置费", 0, 2, true, contextFont);
        OutPutUtils.addcell(table, "其他费用", 0, 1, true, contextFont);
        OutPutUtils.addcell(table, tole1.toPlainString(), 0, 3, true, contextFont);
        OutPutUtils.addcell(table, tole2.toPlainString(), 0, 3, true, contextFont);
        OutPutUtils.addcell(table, tole3.toPlainString(), 0, 2, true, contextFont);
        OutPutUtils.addcell(table, tole4.toPlainString(), 0, 1, true, contextFont);


        OutPutUtils.addcell(table, "其他费用(可以不限于以下其他费用的明细，但需要填写清楚取费依据和说明。)", 0, 12, true, contextFont);
        OutPutUtils.addcell(table, "序号", 0, 0, true, contextFont);
        OutPutUtils.addcell(table, "其他费用明细", 0, 4, true, contextFont);
        OutPutUtils.addcell(table, "计取依据及说明", 0, 4, true, contextFont);
        OutPutUtils.addcell(table, "合价（万元）", 0, 2, true, contextFont);
        OutPutUtils.addcell(table, "备注", 0, 0, true, contextFont);
        for (APCostEntity aPCostEntity : aPCostList) {
            OutPutUtils.addcell(table, aPCostEntity.getPCNum(), 0, 0, true, contextFont);
            OutPutUtils.addcell(table, aPCostEntity.getPCDetail(), 0, 4, true, contextFont);
            OutPutUtils.addcell(table, aPCostEntity.getPCExplain(), 0, 4, false, contextFont);
            OutPutUtils.addcell(table, aPCostEntity.getPCPrice() == null ? "0.00" : aPCostEntity.getPCPrice().toPlainString(), 0, 2, true, contextFont);
            OutPutUtils.addcell(table, aPCostEntity.getPCRemarks(), 0, 0, true, contextFont);
        }
        OutPutUtils.addcell(table, "主要设备", 0, 12, true, contextFont);
        OutPutUtils.addcell(table, "名称", 0, 3, true, contextFont);
        OutPutUtils.addcell(table, "规格及型号", 0, 3, true, contextFont);
        OutPutUtils.addcell(table, "单位", 0, 0, true, contextFont);
        OutPutUtils.addcell(table, "数量", 0, 2, true, contextFont);
        OutPutUtils.addcell(table, "单价（元）", 0, 2, true, contextFont);
        OutPutUtils.addcell(table, "合价（元）", 0, 0, true, contextFont);
        for (DDeviceBuyEntity dDeviceBuyEntity : dDeviceBuyList) {

            OutPutUtils.addcell(table, dDeviceBuyEntity.getDBMidtype(), 0, 3, true, contextFont);
            OutPutUtils.addcell(table, dDeviceBuyEntity.getDBName(), 0, 3, true, contextFont);
            OutPutUtils.addcell(table, dDeviceBuyEntity.getDBUnit(), 0, 0, true, contextFont);
            OutPutUtils.addcell(table, dDeviceBuyEntity.getDBCount() == null ? "0" : dDeviceBuyEntity.getDBCount().toString(), 0, 2, true, contextFont);
            OutPutUtils.addcell(table, dDeviceBuyEntity.getDBPrice() == null ? "0.00" : dDeviceBuyEntity.getDBPrice().toPlainString(), 0, 2, true, contextFont);
            OutPutUtils.addcell(table, dDeviceBuyEntity.getDBPriceall() == null ? "0.00" : dDeviceBuyEntity.getDBPriceall().toPlainString(), 0, 0, true, contextFont);
        }

        OutPutUtils.addcell(table, "主要材料", 0, 12, true, contextFont);
        OutPutUtils.addcell(table, "名称", 0, 3, true, contextFont);
        OutPutUtils.addcell(table, "规格及型号", 0, 3, true, contextFont);
        OutPutUtils.addcell(table, "单位", 0, 0, true, contextFont);
        OutPutUtils.addcell(table, "数量", 0, 2, true, contextFont);
        OutPutUtils.addcell(table, "单价（元）", 0, 2, true, contextFont);
        OutPutUtils.addcell(table, "合价（元）", 0, 0, true, contextFont);
        for (DMaterialBuyEntity dMaterialBuyEntity : dMaterialBuyList) {
            OutPutUtils.addcell(table, dMaterialBuyEntity.getMBMidtype(), 0, 3, true, contextFont);
            OutPutUtils.addcell(table, dMaterialBuyEntity.getMBName(), 0, 3, true, contextFont);
            OutPutUtils.addcell(table, dMaterialBuyEntity.getMBUnit(), 0, 0, true, contextFont);
            OutPutUtils.addcell(table, dMaterialBuyEntity.getMBCount() == null ? "0.00" : dMaterialBuyEntity.getMBCount().toPlainString(), 0, 2, true, contextFont);
            OutPutUtils.addcell(table, dMaterialBuyEntity.getMBPrice() == null ? "0.00" : dMaterialBuyEntity.getMBPrice().toPlainString(), 0, 2, true, contextFont);
            OutPutUtils.addcell(table, dMaterialBuyEntity.getMBPriceall() == null ? "0.00" : dMaterialBuyEntity.getMBPriceall().toPlainString(), 0, 0, true, contextFont);
        }
        OutPutUtils.addcell(table, "项目实施周期（月）或完成时间", 0, 13, true, contextFont);
        OutPutUtils.addcell(table, "序号", 0, 4, true, contextFont);
        OutPutUtils.addcell(table, "时间", 0, 5, true, contextFont);
        OutPutUtils.addcell(table, "事件", 0, 4, true, contextFont);
        for (int i = 0; i < 5; i++) {
            OutPutUtils.addcell(table, "", 0, 4, true, contextFont);
            OutPutUtils.addcell(table, "", 0, 5, true, contextFont);
            OutPutUtils.addcell(table, "", 0, 4, true, contextFont);
        }
        OutPutUtils.addcell(table, "主要附图（另附图纸）", 0, 13, true, contextFont);

        document.add(table);
        Paragraph titles = new Paragraph("      编制：                               审核：                               批准：                ");
        titles.setAlignment(Element.ALIGN_CENTER);
        titles.setFont(qinFont);
        document.add(titles);
    }


    @RequestMapping("/selectone/{guid}")
    public R selectone(@PathVariable("guid") String guid) {
        APBaseEntity aPBase = aPBaseService.queryObject(guid);

        return R.ok().put("aPBase", aPBase);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody APBaseEntity aPBase) {

        aPBase.setPBDatastate("新增");
        aPBase.setPBAddtime(new Date());
        aPBase.setPBHive("10");
        aPBase.setPBState("10");
        aPBase.setIsDraw("是");
        aPBase.setPOperationState("101");

        aPBase.setPBCollectid(aPBase.getPBCollectid().replace("\"", "").replace("[", "").replace("]", ""));
        ValidatorUtils.validateEntity(aPBase, AddGroup.class);

        Map<String, Object> maps = new HashMap<String, Object>();

        String wheres = " 1=1 ";
        if (aPBase.getPBType() != null && !aPBase.getPBType().equals("")) {
            wheres += " and  p_a_type like '%" + aPBase.getPBType() + "%' ";
        } else {
            return R.error("请选择项目类型");
        }

        maps.put("filterSql", wheres + " ");
        List<BProjectApplicationEntity> bProjectApplicationList = bProjectApplicationService.queryList(maps);
        List<BEstimateEntity> bEstimateListall = new ArrayList<BEstimateEntity>();

        if (bProjectApplicationList.size() > 0) {
            aPBase.setAGuid(bProjectApplicationList.get(0).getGuid());
            Map<String, Object> mapss = new HashMap<String, Object>();
            String wheress = " 1=1 ";
            wheress += " and  a_guid = '" + bProjectApplicationList.get(0).getGuid() + "' ";
            wheress += " and  e_type = '" + aPBase.getPBType() + "' ";
            mapss.put("filterSql", wheress + " ");
            List<BEstimateEntity> bEstimateList = bEstimateService.queryList(mapss);


            if (bEstimateList.size() > 0) {

                String SGuid = "";
                for (BEstimateEntity bestimateEntity : bEstimateList) {
                    bEstimateListall.add(bestimateEntity);
                    if (!SGuid.contains(bestimateEntity.getBGuid())) {
                        SGuid += bestimateEntity.getBGuid() + ",";
                    }

                }
                SGuid = SGuid.substring(0, SGuid.length() - 1);
                aPBase.setSGuid(SGuid);
            } else {
                return R.error("所选项目类型没有估算简表，请先配置估算简表");
            }

        } else {
            return R.error("所选项目类型没有申请书，请先配置申请书");
        }
        if (aPBase.getPBOrgid() == null) {
            aPBase.setPBOrgid(getDeptId());
        }

        aPBaseService.save(aPBase);
        //保存其他信息
        APOtherEntity aPOtherEntity = new APOtherEntity();
        aPOtherEntity.setPGuid(aPBase.getGuid());
        aPOtherEntity.setPODatastate("新增");
        aPOtherService.save(aPOtherEntity);
        //保存估算简表
        for (BEstimateEntity bestimateEntity : bEstimateListall) {
            APEstimateEntity APEstimateEntity = new APEstimateEntity();
            APEstimateEntity.setPGuid(aPBase.getGuid());
            APEstimateEntity.setPBGuid(bestimateEntity.getBGuid());
            APEstimateEntity.setPEDatastate("新增");
            APEstimateEntity.setPEItem(bestimateEntity.getEItem());
            APEstimateEntity.setPEName(bestimateEntity.getEName());
            APEstimateEntity.setPESysRatio(bestimateEntity.getESysRatio());
            APEstimateEntity.setPEOwnRatio(bestimateEntity.getEOwnRatio());
            APEstimateEntity.setPEInitial(BigDecimal.ZERO);
            APEstimateEntity.setPEFinal(BigDecimal.ZERO);
            aPEstimateService.save(APEstimateEntity);
        }
        //其他费用表
        Map<String, Object> mapss = new HashMap<String, Object>();

        String wheress = " 1=1 ";
        wheress += " and  a_guid = '" + aPBase.getAGuid() + "' ";
        mapss.put("filterSql", wheress + " ");
        List<BOtherCostEntity> bOtherCostList = bOtherCostService.queryList(mapss);
        for (BOtherCostEntity BOtherCostEntity : bOtherCostList) {
            APCostEntity aPCostEntity = new APCostEntity();
            aPCostEntity.setPCDatastate("新增");
            aPCostEntity.setPGuid(aPBase.getGuid());
            aPCostEntity.setPCNum(BOtherCostEntity.getOCNum());
            aPCostEntity.setPCDetail(BOtherCostEntity.getOCDetail());
            aPCostEntity.setPCExplain(BOtherCostEntity.getOCExplain());
            aPCostEntity.setPCSort(BOtherCostEntity.getOCSort());
            aPCostEntity.setPCToll(BOtherCostEntity.getOCToll());
            aPCostEntity.setPCPrice(BigDecimal.ZERO);
            aPCostService.save(aPCostEntity);
        }


        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody APBaseEntity aPBase) {

        aPBase.setPBDatastate("修改");
        if (aPBase.getBGuid() != null && aPBase.getBGuid() != "") {
            aPBase.setPBHive("20");
        } else {
            aPBase.setPBHive("10");
        }
        aPBase.setPBCollectid(aPBase.getPBCollectid().replace("\"", "").replace("[", "").replace("]", ""));
        ValidatorUtils.validateEntity(aPBase, UpdateGroup.class);
        if (aPBase.getPBCollectid() == null || aPBase.getPBCollectid().equals("")) {
            return R.error("参与人员不能为空");
        }


        aPBaseService.update(aPBase);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody String[] guids) {

        aPBaseService.deleteBatch(guids);

        return R.ok();
    }

    @RequestMapping("/gotosg")
    public R gotosg(@RequestBody String guid) {
        APBaseEntity aPBase = aPBaseService.queryObject(guid);
        if (!aPBase.getPBState().equals("30")) {
            return R.error("项目没有在归档阶段，请先归档在进入施工阶段");
        }
        CPBaseEntity cPBase = cPBaseService.queryObject(guid);
        if (cPBase != null) {
            return R.error("项目在施工阶段已经存在，请在施工阶段进行查看");
        }
        cPBase = new CPBaseEntity();
        try {
            BeanUtils.copyProperties(cPBase, aPBase);
            cPBase.setPBState("10");
            cPBaseService.save(cPBase);
            for (int i = 1; i < 9; i++) {
                String nuame = "";
                switch (i) {
                    case 1:
                        nuame = "施工复测";
                        break;
                    case 2:
                        nuame = "安全技术交流";
                        break;
                    case 3:
                        nuame = "现场开工";
                        break;
                    case 4:
                        nuame = "材料到场";
                        break;
                    case 5:
                        nuame = "中间检查";
                        break;
                    case 6:
                        nuame = "现场安全监督";
                        break;
                    case 7:
                        nuame = "现场施工质量监督";
                        break;
                    case 8:
                        nuame = "竣工自检";
                        break;
                }


                CScheduleEntity cScheduleEntity = new CScheduleEntity();
                cScheduleEntity.setControlPoint("否");
                cScheduleEntity.setSSort(i);
                cScheduleEntity.setSDatastate("新增");
                cScheduleEntity.setPGuid(cPBase.getGuid());
                cScheduleEntity.setPName(cPBase.getPBName());
                cScheduleEntity.setSName(nuame);
                cScheduleService.save(cScheduleEntity);

            }

        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (InvocationTargetException e) {
            e.printStackTrace();
        }
        return R.ok();
    }


    @RequestMapping("/gotoys")
    public R gotoys(@RequestBody String guid) {
        APBaseEntity aPBase = aPBaseService.queryObject(guid);
        if (!aPBase.getPBState().equals("30")) {
            return R.error("项目没有在归档阶段，请先归档在进入验收阶段");
        }
        EPBaseEntity ePBase = ePBaseService.queryObject(guid);
        if (ePBase != null) {
            return R.error("项目在验收阶段已经存在，请在验收阶段进行查看");
        }
        ePBase = new EPBaseEntity();
        try {
            BeanUtils.copyProperties(ePBase, aPBase);
            ePBase.setPBState("10");
            ePBaseService.save(ePBase);
            Map<String, Object> mapss = new HashMap<String, Object>();
            String wheres = " 1=1 ";
            wheres += " and  p_guid = '" + guid + "' ";
            mapss.put("filterSql", wheres + " ");
            List<APRangeEntity> aPRangeList = aPRangeService.queryList(mapss);
            for (APRangeEntity aPRangeEntity : aPRangeList) {
                EPRangeEntity ePRangeEntity = new EPRangeEntity();
                BeanUtils.copyProperties(ePRangeEntity, aPRangeEntity);
                ePRangeService.save(ePRangeEntity);
            }
            List<APWireEntity> aPWireList = aPWireService.queryList(mapss);
            for (APWireEntity aPWireEntity : aPWireList) {
                EPWireEntity ePWireEntity = new EPWireEntity();
                BeanUtils.copyProperties(ePWireEntity, aPWireEntity);
                ePWireService.save(ePWireEntity);
            }
            List<DPointEntity> dPointList = dPointService.queryList(mapss);
            for (DPointEntity dPointEntity : dPointList) {
                EPointEntity ePointEntity = new EPointEntity();
                BeanUtils.copyProperties(ePointEntity, dPointEntity);
                ePointService.save(ePointEntity);
            }
            List<DCrossCostEntity> dCrossCostList = dCrossCostService.queryList(mapss);
            for (DCrossCostEntity dCrossCostEntity : dCrossCostList) {
                ECrossCostEntity eCrossCostEntity = new ECrossCostEntity();
                BeanUtils.copyProperties(eCrossCostEntity, dCrossCostEntity);
                eCrossCostService.save(eCrossCostEntity);
            }
            List<DDrawLineEntity> dDrawLineList = dDrawLineService.queryList(mapss);
            for (DDrawLineEntity dDrawLineEntity : dDrawLineList) {
                EDrawLineEntity eDrawLineEntity = new EDrawLineEntity();
                BeanUtils.copyProperties(eDrawLineEntity, dDrawLineEntity);
                eDrawLineService.save(eDrawLineEntity);
            }
            List<DDeviceBuyEntity> dDeviceBuyList = dDeviceBuyService.queryList(mapss);
            for (DDeviceBuyEntity dDeviceBuyEntity : dDeviceBuyList) {
                EDeviceBuyEntity eDeviceBuyEntity = new EDeviceBuyEntity();
                BeanUtils.copyProperties(eDeviceBuyEntity, dDeviceBuyEntity);
                eDeviceBuyService.save(eDeviceBuyEntity);
            }
            List<DDeviceOldEntity> dDeviceOldList = dDeviceOldService.queryList(mapss);
            for (DDeviceOldEntity dDeviceOldEntity : dDeviceOldList) {
                EDeviceOldEntity eDeviceOldEntity = new EDeviceOldEntity();
                BeanUtils.copyProperties(eDeviceOldEntity, dDeviceOldEntity);
                eDeviceOldService.save(eDeviceOldEntity);
            }
            List<DMaterialBuyEntity> dMaterialBuyList = dMaterialBuyService.queryList(mapss);
            for (DMaterialBuyEntity dMaterialBuyEntity : dMaterialBuyList) {
                EMaterialBuyEntity eMaterialBuyEntity = new EMaterialBuyEntity();
                BeanUtils.copyProperties(eMaterialBuyEntity, dMaterialBuyEntity);
                eMaterialBuyService.save(eMaterialBuyEntity);
            }
            List<DMaterialOldEntity> dMaterialOldList = dMaterialOldService.queryList(mapss);
            for (DMaterialOldEntity dMaterialOldEntity : dMaterialOldList) {
                EMaterialOldEntity eMaterialOldEntity = new EMaterialOldEntity();
                BeanUtils.copyProperties(eMaterialOldEntity, dMaterialOldEntity);
                eMaterialOldService.save(eMaterialOldEntity);
            }
            List<DWorkContentEntity> dWorkContentList = dWorkContentService.queryList(mapss);
            for (DWorkContentEntity dWorkContentEntity : dWorkContentList) {
                EWorkContentEntity eWorkContentEntity = new EWorkContentEntity();
                BeanUtils.copyProperties(eWorkContentEntity, dWorkContentEntity);
                eWorkContentService.save(eWorkContentEntity);
            }
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (InvocationTargetException e) {
            e.printStackTrace();
        }
        return R.ok();
    }

    /**
     * 项目归档
     *
     * @param guid
     * @return
     */
    @RequestMapping("/upbasetjsh")
    public R upbasetjsh(@RequestBody String guid) {
        APBaseEntity aPBase = aPBaseService.queryObject(guid);
        aPBase.setPBState("20");
        aPBase.setPOperationState("104");
        aPBaseService.update(aPBase);
        return R.ok();
    }

    /**
     * 项目审核
     *
     * @param guid
     * @return
     */
    @RequestMapping("/projectAudit")
    public R projectAudit(String guid, String shyj, boolean isPass) {
        APBaseEntity aPBase = aPBaseService.queryObject(guid);
        if (isPass) {    //	审核通过后就可以归档
            aPBase.setPOperationState("106");
            aPBase.setPAuditOpinion(shyj);
            aPBase.setPBState("30");
        } else {    //	审核不通过，则打回到踏勘
            aPBase.setPOperationState("105");
            aPBase.setPAuditOpinion(shyj);
            aPBase.setPBState("10");
        }
        aPBaseService.update(aPBase);
        return R.ok();
    }


}
